Cod sursa(job #1506035)
Utilizator | Data | 19 octombrie 2015 22:42:09 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include<fstream>
using namespace std;
const long long N=1999999973;
long long n,p;
long long pow(long long x, long long y)
{
long long a=1;
while(y!=0)
{
if(y%2==1)
{
y=y-1;
a=(a*x)%N;
}
x=(x*x)%N;
y=y/2;
}
return a;
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin>>n>>p;
fout<<pow(n,p);
}