Cod sursa(job #2545005)
Utilizator | Data | 12 februarie 2020 19:15:21 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#include <iostream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int pow(int n, int p) {
int r = 1;
while(p) {
if(p % 2)
r *= (1LL * n) % MOD;
n *= (1LL * n) % MOD;
p /= 2;
}
return r % MOD;
}
int main() {
int n, p;
fin >> n >> p;
fout << pow(n, p);
}