Cod sursa(job #1505880)
Utilizator | Data | 19 octombrie 2015 20:31:44 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include<cstdio>
using namespace std;
const long long nr=1999999973;
long long n,p;
long long putere(long long x,long long y)
{
long long a=1;
while(y!=0)
{
if(y%2==1)
{
y=y-1;
a=(a*x)%nr;
}
x=(x*x)%nr;
y=y/2;
}
return a;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld",&n,&p);
printf("%lld\n",putere(n,p));
}