Cod sursa(job #2691468)
| Utilizator | Data | 28 decembrie 2020 19:42:35 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int putere(int a, int b, int c) {
if (b == 0)
return 1;
if (b % 2 != 0)
return (a * putere(a, b - 1, c)) % c;
else {
return ((putere(a, b/2, c) % c) * (putere(a, b/2, c) % c)) % c;
}
}
int main () {
long long N, P;
fin >> N >> P;
fout << putere(N, P, 1999999973);
}
