-
Notifications
You must be signed in to change notification settings - Fork 0
/
13171.cpp
34 lines (31 loc) · 795 Bytes
/
13171.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#define MODIFIER 1000000007
#include <iostream>
using namespace std;
long long sq_lst[64];
int main(){
long long a,x;
cin >> a >> x;
sq_lst[0] = a % MODIFIER;
for(int i=1;i<=60;i++){
sq_lst[i] = ((sq_lst[i-1] % MODIFIER) * (sq_lst[i-1] % MODIFIER)) % MODIFIER;
}
long long ans = 1;
while(x > 0){
long long i = ((long long)1<<(long long)60);
int idx = 60;
for(;i>1;i>>=1){
if(i <= x){
x -= i;
ans = ((ans % MODIFIER) * (sq_lst[idx]) % MODIFIER) % MODIFIER;
break;
}
idx -= 1;
}
if(i == 1){
x -= 1;
ans = ((ans % MODIFIER) * (a % MODIFIER)) % MODIFIER;
}
}
cout << ans << '\n';
return 0;
}