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