Cod sursa(job #812661)
Utilizator | Data | 14 noiembrie 2012 10:14:58 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <cstdlib>
#include <cstdio>
#define mod 1999999973
int n,p,rez;
int main ()
{
FILE *f,*g;
f = fopen("lgput.in","r");
g = fopen("lgput.out","w");
fscanf(f,"%d%d",&n,&p);
int rez=1;
while (p)
{
if (p%2) rez=(rez*n)%mod;
n=(n*n)%mod;
p >>=1;
}
fprintf(g,"%d",rez);
fclose(f);
fclose(g);
//system("pause");
return 0;
}