Cod sursa(job #2257256)
| Utilizator | Data | 9 octombrie 2018 21:09:31 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
int power(int x, int y) {
if (y == 0) {
return 1;
}
int r = power(x, y / 2);
if (y % 2 == 0) {
return (1LL * r * r) % MOD;
} else {
return (1LL * x * r) % MOD * r;
}
}
int main() {
int N, P;
fin >> N >> P;
fout << power(N, P);
}