Cod sursa(job #180512)
Utilizator | Data | 17 aprilie 2008 09:42:54 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include<stdio.h>
#define dim 1999999973
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int n,p,d=1;
scanf("%d%d",&n,&p);
for(p=p;p>0;p/=2)
{
if(p%2==1)
d=(d*n)%dim;
n=(n*n)%dim;
}
printf("%d",d);
return 0;
}