Cod sursa(job #333913)
Utilizator | Data | 24 iulie 2009 16:24:01 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include<stdio.h>
#define m 1999999973
long n, x;
long po(long x, long n)
{
if(n==1)return x;
else if(n%2)return x*po((x%m),n-1);
else return po((x%m)*(x%m),n/2);
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%ld %ld",&x, &n);
printf("%ld",po(x, n));
return 0;
}