Cod sursa(job #2823500)
Utilizator | Posea Teodor Teodor11 | Data | 28 decembrie 2021 18:14:37 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
int rest(long long a, int b, long long p) {
if (p == 0) {
return 1;
}
if (p % 2 == 1) {
return ((a % b) * (rest(a, b, p - 1) % b)) % b;
}
return ((rest(a, b, p / 2) % b) * (rest(a, b, p / 2) % b)) % b;
}
int main() {
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p;
fin >> n >> p;
fout << rest(n, 1999999973, p);
return 0;
}