Cod sursa(job #2290516)
| Utilizator | Data | 26 noiembrie 2018 17:04:01 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long Int;
Int n,a,sol,phi,p,q,MOD;
inline Int putere(Int b,Int e)
{
if(e==0)
return 1;
Int r=putere(b,e/2);
r=r*r%MOD;
if(e%2)
r=r*b%MOD;
return r;
}
int main()
{
fin>>a>>n;
MOD=n;
phi=1;
for(p=2;p*p<=n;p++)
if(n%p==0)
{
n/=p;phi*=p-1;
while(n%p==0)
{
n/=p;
phi*=p;
}
}
if(n>1)
phi*=n-1;
cerr<<phi;
sol=putere(a,phi-1);
fout<<sol;
return 0;
}
