Cod sursa(job #1605256)
Utilizator | Data | 18 februarie 2016 21:11:18 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <cstdio>
#define mod 1999999973
int main(){
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
long long n,p,x;
scanf("%lld %lld",&n,&p);
x=1;
while(p>1)
{
if(p%2)
{
x=(x*n)%mod;
n=(n*n)%mod;
p=(p-1)/2;
}
else
{
n=(n*n)%mod;
p/=2;
}
}
printf("%lld",(n*x)%mod);
return 0;
}