Cod sursa(job #394432)
Utilizator | Data | 10 februarie 2010 21:28:29 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include<stdlib.h>
#include<cstdio>
const int m = 1999999973;
int main()
{long long p,n,i, a,rez;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld", &n, &p);
a = n; rez = 1;
for (i = 0; (1<<i) <= p; ++i)
{
if ( ((1<<i) & p) > 0)
rez = (rez * a) % m;
a = (a * a) % m;
}
printf("%lld",rez);
return 0;
}