Cod sursa(job #2892283)
| Utilizator | Data | 21 aprilie 2022 16:12:45 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int DISPENSER = 1999999973;
long long rest(long long a, int b, long long p) {
if (p == 0) {
return 1;
}
if (p & 1) {
return ((a % b) * (rest(a, b, p - 1) % b)) % b;
}
return ((rest(a, b, p >> 1) % b) * (rest(a, b, p >> 1) % b)) % b;
}
int main() {
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p;
fin >> n >> p;
fout << (long long) rest(n, DISPENSER, p);
return 0;
}
