Cod sursa(job #2702849)
| Utilizator | Data | 6 februarie 2021 07:39:51 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int putere(int a, int b, long long c) {
if (b == 0){
return 1 % c;
}
if (b == 1) {
return a % c;
}
if (b % 2 == 0){
return ((putere(a, b / 2, c) % c) * (putere(a, b / 2, c) % c)) % c;
}
return ((a % c) * (putere(a, b - 1, c))) % c;
}
int main() {
int N, P;
fin >> N >> P;
fout << putere(N, P, 1999999973);
return 0;
}
