Cod sursa(job #3134651)
Utilizator | Data | 30 mai 2023 01:48:24 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <iostream>
using namespace std;
const int m = 1999999973;
int main() {
int n, p;
long long a, sol = 1;
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
cin >> n >> p;
a = n;
while (p > 0) {
if (p % 2 == 1) {
sol = (sol * a) % m;
}
a = (a * a) % m;
p /= 2;
}
cout << sol;
}