Cod sursa(job #627481)
Utilizator | Data | 30 octombrie 2011 01:11:31 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include<cstdio>
int n, p;
long long PutereLog(int n, int p)
{
long long x = 1;
while(p > 0)
{
if(p & 1)
{
x = x * n;
p--;
}
n = n * n;
p /= 2;
}
return x;
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d %d", &n, &p);
printf("%lld\n", PutereLog(n, p) % 1999999973);
return 0;
}