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