Cod sursa(job #627476)
Utilizator | Data | 30 octombrie 2011 01:00:21 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include<cstdio>
int n, p;
int PutereLog(int n, int p)
{
int 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("%d", PutereLog(n, p));
return 0;
}