Cod sursa(job #2959302)
| Utilizator | Data | 30 decembrie 2022 16:36:46 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| 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;
fin >> a >> b;
fout << log_exp(a % 1999999973, b);
}
