Cod sursa(job #928412)
Utilizator | Data | 26 martie 2013 13:59:05 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include<cstdio>
const long mod = 1999999973;
long n,p;
long expBySquaring(long x,long n)
{
if (n==1) return x;
else if (n%2) return (x*expBySquaring (x*x%mod,(n-1)/2))%mod;
else return (expBySquaring(x*x,n/2))%mod;
}
int main()
{
FILE*f;
f = fopen("lgput.in","r");
fscanf(f,"%ld %ld",&n,&p);
fclose(f);
f = fopen("lgput.out","w");
fprintf(f,"%ld",expBySquaring(n,p));
fclose(f);
return 0;
}