Cod sursa(job #1916213)
Utilizator | Data | 9 martie 2017 08:37:23 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
#define M 1999999973LL
long long n, p, r;
int main()
{
fin >> n >> p;
r = 1;
for(int i = 0; (1 << i) <= p; ++i){
if(p & (1 << i))
r = (r * n) % M;
n = (n * n) % M;
}
fout << r;
return 0;
}