Cod sursa(job #2557431)
| Utilizator | Data | 25 februarie 2020 19:49:30 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int m = 1999999973;
int fast_exp(int base, int exponent) {
long solution = 1;
long long a = base;
for (int i = 0; (1 << i) <= exponent; ++i) {
if (((1 << i) & exponent) > 0) {
solution = (solution * a) % m;
}
a = (a * a) % m;
}
return solution;
}
int main() {
long long base, exponent;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
cin >> base >> exponent;
cout << fast_exp(base, exponent) << '\n';
return 0;
}