Cod sursa(job #394052)
Utilizator | Data | 10 februarie 2010 13:54:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include<stdlib.h>
#include<cstdio>
const int m = 1999999973;
int main()
{int p,n,i;
long a,rez;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d", &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("%d",rez);
return 0;
}