Cod sursa(job #431763)
Utilizator | Data | 1 aprilie 2010 13:16:15 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <stdio.h>
#include <string.h>
const int nmax = 10001;
const int m = 1999999973;
int main()
{
unsigned int i, n, p;
long long a, sol = 1;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d", &n, &p);
a=n;
for (i=0; (1<<i)<=p;++ i)
{
if ( ((1<<i)&p)>0)
sol=sol*a%m;
a=a*a%m;
}
printf("%lld\n", sol);
}