-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExponentiation.cpp
137 lines (115 loc) · 4.47 KB
/
Exponentiation.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/// say Alhamdulillah
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define init \
ll count = 0, zz, t; \
cin >> t; \
while (t--)
#define ld long double
#define ed "\n"
#define eb emplace_back
#define con continue
#define bre break
#define pl " "
#define size size()
#define mpr make_pair
#define vec vector<ll>
#define lmax LONG_LONG_MAX
#define lmin LONG_LONG_MIN
#define forr(i, a, b) for (ll i = a; i < b; i++)
#define forrev(i, a, b) for (ll i = a; i >= b; i--)
// #define v.all v.begin(),v.end()
#define printarr(arr, in, n) \
cout << ed; \
for (ll i = in; i < n; i++) \
cout << arr[i] << " "; \
cout << ed;
#define print(arr, n) \
cout << ed; \
for (ll i = 0; i < n; i++) \
cout << arr[i] << " "; \
cout << ed;
#define printyn(flag) \
if (flag == 0) \
cout << "NO\n"; \
else \
cout << "YES\n";
#define printvc(vc) \
cout << ed; \
for (auto x : vc) \
cout << x << " "; \
cout << ed;
// #define printvc(vc) for(auto x:vc)cout<<x<<".";
// #define printvc(vc,in,n) cout<<ed;for(ll i=in;i<n;i++)cout<<arr[i]<<"
// ";cout<<ed;
#define sortt(arr, n) sort(arr, arr + n);
#define sorttvc(v) sort(v.begin(), v.end());
#define rev(v) reverse(v.begin(), v.end());
// #define find(v,x) find(v.begin(), v.end(),x);
// string binary = bitset<32>(n).to_string();
// unsigned long decimal =bitset<8>(binary).to_ulong();
ll recurr(ll a, ll b) {
if (b == 1)
return a % MOD;
else if (b == 0)
return 1;
else {
if (b % 2 == 0) {
ll x = recurr(a, b / 2);
return (x * x) % MOD;
} else {
ll x = recurr(a, b / 2);
return ((x * x) % MOD * a) % MOD;
}
}
}
int main() {
// fast
init {
count++;
ll i, j, x, y, d, p, q, g, m = 0, n = 0, rest = 0, k, ans = 0, flag = 1,
sum = 0, bef_even_pos = 0, bef_odd_pos = 0;
ll mini = lmax, maxi = -1, dif = 0, total = 0, same = 0, plus = 0,
minus = 0, zero = 0;
ll piv = 0, piv1 = 21, piv2 = 21, rem = 0, fix = 0, flex = 0, change = 0,
prev = -1, l = 0, r = 0, l1, l2, r1, r2, lval, rval, now = 0, mid;
// string s, s1 = "", s2 = "", res1 = "", res2 = "", chk1 = "", chk2 = "",
// chk3 = "", chk4 = ""; string pivs = "", rems = "";
// cin >> n ;
// n = s.size;
ll arr[n];
// ll number[n], cost[n], forsum[n], backsum[n];
// vector<vec> vdarr(n, vec(10, 0));
vector<ll> v, v1, v2, vans, vpos, vlen, vsum, vdif;
vector<pair<ll, ll>> vpr;
pair<ll, ll> pr, pr1, pr2;
set<ll> st, st1, st2, ms, ldiff, rdiff;
priority_queue<ll> pq, pq1, pq2;
stack<ll> stck, stck1, stck2;
map<ll, ll> mp, mp1, mp2, sizearr;
queue<ll> vq[10], vq1, vq2;
deque<ll> dq, dq1, dq2;
// Point pa,pb,pt[n];
// Node pa,pb,pt[n];
// cout<<"-----------------yess"<<endl;
// string binary = bitset<>(n).to_string();
// reverse(binary.begin(), binary.end());
// cout<<binary<<endl;
// cout<<LONG_MAX<<endl;
// cout<<(n|(n>>1))<<endl;
// return 0;
// forr(i,0,n)
{
cin >> x >> y;
cout << recurr(x, y) << endl;
}
}
// cout<<ans<<endl;
// ans = 0;
}