Cod sursa(job #2958772)
| Utilizator | Data | 28 decembrie 2022 11:44:05 | |
|---|---|---|---|
| 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>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int log_exp(long long a, long long b) {
if (b == 1) {
return a;
}
if (b % 2 == 0) {
long long ok = log_exp(a, b / 2);
cout << ok * ok << "\n";
return ok * ok;
}
return a * log_exp(a, b - 1);
}
int main() {
long long a, b;
cin >> a >> b;
cout << log_exp(a, b) % 1999999973;
}
