Cod sursa(job #1999013)
Utilizator | Data | 9 iulie 2017 23:07:09 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const int mod=1999999973;
int n,p;
long long rec(int x)
{
if(x==0)
return 1;
if(x==1)
return n%mod;
else if(x%2)
{
return (n*rec(x-1))%mod;
}
else
{
int c=rec(x/2);
return (c*c)%mod;
}
}
int main()
{
f>>n>>p;
g<<rec(p);
return 0;
}