Cod sursa(job #3205084)
| Utilizator | Data | 18 februarie 2024 19:03:01 | |
|---|---|---|---|
| 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;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long putere(long long n, long long p) {
if (p <= 0) {
return 1;
} if (p % 2 == 0) {
return putere(n * n % 1999999973, p / 2) % 1999999973;
} else if (p % 2 == 1) {
return n * putere(n * n % 1999999973, (p - 1) / 2)% 1999999973;
}
}
int main() {
long long n, p;
fin >> n >> p;
fout << putere(n, p) % 1999999973;
}
