Cod sursa(job #2638814)
Utilizator | Data | 30 iulie 2020 00:33:29 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
int MOD = 1999999973;
int lgput(int x, int n) {
if (n == 1) {
return x;
} else if (n % 2 == 0) {
return lgput (1LL * x * x % MOD, n / 2);
} else {
return 1LL * x * lgput(x * x, (n - 1)/2) % MOD;
}
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
fin >> n >> p;
fout << lgput(n, p);
return 0;
}