Cod sursa(job #2375281)
Utilizator | Data | 7 martie 2019 23:57:40 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
#include <cstring>
#define mod 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n,p,x,nr;
int main()
{
fin>>n>>p;
nr=n;x=1;
while(x<p)
{
if(x%2==0&&x*2<=p)
{
nr=(nr*nr)%mod;
x=x*2;
}
else
{
nr=(nr*n)%mod;
x++;
}
}
fout<<nr;
return 0;
}