Cod sursa(job #1495474)
Utilizator | Data | 3 octombrie 2015 10:02:25 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.61 kb |
#include <iostream>
#include <cstdio>
using namespace std;
int mod = 1999999973;
long long f(long long n, long long p)
{
if(p==1)
{
return n%mod;
}
if(p == 2)
{
return (n*n)%mod;
}
if(p%2==1)
{
int x = f(n,p/2)%mod;
return ((x*x%mod)*n)%mod;
}
else if(p%2==0)
{
int x = f(n,p/2)%mod;
return (x*x%mod);
}
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
long long n, p;
scanf("%lld%lld",&n,&p);
cout<<f(n%mod,p%mod);
return 0;
}