Cod sursa(job #1176463)
Utilizator | Data | 26 aprilie 2014 10:01:21 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <cstdio>
using namespace std;
FILE *f=fopen ("inversmodular.in","r");
FILE *g=fopen ("inversmodular.out","w");
int main(){
int n,k;
long long a=0,p=1;
fscanf (f,"%lld%d",&a,&n);
k=n-2;
while (k>0){
if (k%2==1){
p=((p%n)*(a%n))%n;
k--;
}
a=((a%n)*(a%n))%n;
k/=2;
}
fprintf (g,"%lld",p);
return 0;
}