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