Cod sursa(job #2704901)
| Utilizator | Data | 11 februarie 2021 16:24:07 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
#define ll long long
#define MOD 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
ll fast_pow(ll n, ll p) {
ll ans = 1;
for (int i = 0; i <= 32; i++) {
if (p & (1ll << i)) {
ans = (ans * n) % MOD;
}
n = (n * n) % MOD;
}
return ans;
}
int main() {
ll n, p;
in >> n >> p;
out << fast_pow(n, p);
return 0;
}