Cod sursa(job #1164196)

Utilizator UVS_Elfus_Deneo_KiraUVS-Elfus-Dutzul-Kira UVS_Elfus_Deneo_Kira Data 1 aprilie 2014 22:13:30
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include<fstream>
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#include<queue>
#define f cin
#define g cout
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll unsigned long long
#define bit 20
#define inf 500000000
#define base 256
#define ba 255
#define N 10100
#define mod  1999999973
#define inu "inversmodular.in"
#define outu "inversmodular.out"
using namespace std;
ifstream f(inu);
ofstream g(outu);
//int dx[]={0,0,0,1,-1};
//int dy[]={0,1,-1,0,0};
vector<int> v[N];
ll n,po,i,phi,mo;
ll rise(ll x,ll po)
{
	ll sol=1;
	while(po)
	{
		if(po&1)
			sol=sol*x%mo;
		x=x*x%mo;
		po>>=1;
	}
	return sol;
}
int main ()
{
	f>>n>>po;
	mo=po;
	phi=po;
	for(i=2;i*i<=po;++i)
		if(po%i==0)
		{
			phi=phi/i*(i-1);
			while(po%i==0)
				po/=i;
		}
	if(po!=1)
	{
		phi=phi/po*(po-1);
	}
	g<<rise(n,phi-1);
	return 0;
}