Cod sursa(job #1436137)
Utilizator | Data | 15 mai 2015 11:18:11 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <cstdio>
#include <cmath>
FILE*f=fopen("inversmodular.in","r");
FILE*g=fopen("inversmodular.out","w");
unsigned long long p=1,x=1,N,n;
int main()
{
fscanf(f,"%d %d\n",&x,&N);
n = N - 2;
while(n)
if(n % 2 == 0)
{
x = (x * x) % N;
n /= 2;
}
else
{
p = (p * x) % N;
n--;
}
fprintf(g,"%d\n",p);
}