Cod sursa(job #2545009)
Utilizator | Data | 12 februarie 2020 19:18:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
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 * r * n) % MOD;
n = (1LL * n * n) % MOD;
p /= 2;
}
return r;
}
int main() {
int n, p;
fin >> n >> p;
fout << pow(n, p);
}