Cod sursa(job #2001593)
Utilizator | Data | 17 iulie 2017 10:01:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
long long n, p , pwr , np = 1;
fin >> n >> p;
pwr = n;
while(p!=0)
{
if(p%2==0)
{
pwr *= pwr;
pwr %= 1999999973;
p/=2;
}
else
{
np*=pwr;
np %= 1999999973;
pwr *= pwr;
pwr %= 1999999973;
p=(p-1)/2;
}
}
fout << np;
return 0;
}