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