Cod sursa(job #2568274)
Utilizator | Matei Alexandru AlexGFX | Data | 3 martie 2020 21:47:13 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
int MOD = 1999999973;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int lgput(int n, int p) {
int res = 1;
while(p > 0) {
if(p % 2 == 1) {
res = (1LL * res * n) % MOD;
}
p = p/2;
n = (1LL* n*n) % MOD;
}
return res;
}
int main() {
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
int n, p;
fin >> n >> p;
fout << lgput(n, p);
}