Cod sursa(job #3141167)
Utilizator | Ionescu Raul David ionescuraul26 | Data | 13 iulie 2023 09:26:20 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const long long DIVISOR = 1999999973;
long long power(long long a, long long b) {
if (b == 0) {
return 1;
}
long long num = power(a, b / 2);
if (b % 2 == 0) {
return num * num % DIVISOR;
}
return (num % DIVISOR) * ((num * % DIVISOR) % DIVISOR) * (a % DIVISOR) % DIVISOR;
}
int main() {
int n, p;
fin >> n >> p;
fout << power(n, p);
return 0;
}