Cod sursa(job #3277886)
| Utilizator | Data | 17 februarie 2025 19:36:11 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
// N ^ P O(log P), nu vrem O(P)
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int m = 1999999973;
int exponentiere_rapida(int N, int P) {
if(P == 1)
return N;
int aux = exponentiere_rapida(N, P / 2);
int rezultat = (1LL * aux * aux) % m;
if(P % 2 == 1)
rezultat = (1LL * rezultat * P) % m;
return rezultat;
}
int main()
{
int N, P;
fin >> N >> P;
fout << exponentiere_rapida(N, P);
return 0;
}
