Cod sursa(job #2535425)
| Utilizator | Data | 31 ianuarie 2020 20:54:20 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1999999973;
long long n, p;
long long lgpow(int n, int p) {
int sol = 1;
while (n) {
if (p & 1)
sol = n * p % mod;
p >>= 1;
n *= n % mod;
}
return sol;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
cin >> n >> p;
cout << lgpow(n, p);
}
