Cod sursa(job #226685)
Utilizator | Data | 2 decembrie 2008 13:40:12 | |
---|---|---|---|
Problema | Invers modular | Scor | Ascuns |
Compilator | cpp | Status | done |
Runda | Marime | 0.34 kb |
#include<stdio.h>
#define LL long long
LL N,M;
int main()
{
freopen("invers.in","r",stdin);
freopen("invers.out","w",stdout);
scanf("%lld %lld\n",&N,&M);
LL nr = N;
LL crt = 1;
LL put = M - 2;
for(LL p = 1;p <= put;p <<= 1)
{
if (p & put) crt = (crt * nr) % M;
nr = (nr * nr) % M;
}
printf("%lld\n",crt);
return 0;
}