Cod sursa(job #1124281)
Utilizator | Data | 26 februarie 2014 11:58:19 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MO = 1999999973;
long long N, P, Sol;
int main() {
fin >> N >> P;
Sol = 1;
while (P) {
if (P % 2)//odd
Sol = (Sol * N) % MO;
N = (N * N) % MO;
P /= 2;
}
fout << Sol << '\n';
fin.close();
fout.close();
return 0;
}