Cod sursa(job #228011)
| Utilizator | Data | 6 decembrie 2008 10:32:43 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
using namespace std;
typedef long long int64;
int64 n, p;
int64 M = 1999999973LL;
int64 memo[34];
int main() {
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
cin >> n >> p;
memo[0] = n;
int64 i;
for (i = 1; i < 33; ++i) memo[i] = (memo[i-1] * memo[i-1])%M;
int64 ret = 1;
int64 bit = 1;
int64 pos = 0;
while (bit <= p) {
if (p & bit) {ret*=memo[pos], ret%=M;}
bit*=2LL; pos++;
}
cout << ret << '\n';
return 0;
}
