Cod sursa(job #561221)
| Utilizator | Data | 19 martie 2011 07:49:49 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include<stdio.h>
#define x 1999999973
FILE *f=fopen("lgput.in","r");
FILE *g=fopen("lgput.out","w");
long long a,b,P,meg;
int main () {
fscanf(f,"%lld %lld",&a,&b);
meg = 1; P = a;
while ( b ){
if ( b % 2 )
meg = ( meg * P ) % x;
P = ( P * P ) % x;
b = b/2;
}
fprintf(g,"%lld\n",meg);
fclose(f);
fclose(g);
return 0;
}