Cod sursa(job #2758068)
| Utilizator | Data | 8 iunie 2021 14:48:03 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long putere(long long a, long long b, int c) {
if (b == 0) {
return 1;
}
if (b % 2 == 0) {
return (putere(a, b / 2, c) * putere(a, b / 2, c)) % c;
}
return a * putere(a, b - 1, c) % c;
}
int main() {
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p;
fin >> n >> p;
fout << putere(n, p, 1999999973);
return 0;
}
