Cod sursa(job #211819)
Utilizator | Data | 3 octombrie 2008 18:19:07 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.25 kb |
#include<stdio.h>
int main()
{
int a,n,p;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d%d",&n,&p);
a=1;
while(p!=0)
{
if(p%2!=0)
{
a=a*n;
n=n*n;
p=p/2;
}
}
printf("%d",a);
return 0;
}