Cod sursa(job #2290512)
| Utilizator | Data | 26 noiembrie 2018 16:57:44 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long Int;
const Int MOD = 1999999973LL;
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 n,a,sol,phi,p,q;
int main()
{
fin>>a>>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;
sol=putere(a,phi-1);
fout<<sol;
return 0;
}
