-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinExp.cpp
More file actions
36 lines (30 loc) · 730 Bytes
/
Copy pathBinExp.cpp
File metadata and controls
36 lines (30 loc) · 730 Bytes
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
#include <bits/stdc++.h>
#define _ \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define endl '\n'
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
// a ^ b = ans (mod m)
int binpow(int a, int b, int m) {
int ret = 1;
while (b) {
// b % 2 == 1
if (b & 1)
ret = 1ll * ret * a % m;
a = 1ll * a * a % m;
b /= 2;
}
return ret;
}
int main() {
int a, b, m;
cin >> a >> b >> m;
cout << binpow(a, b, m) << endl;
return 0;
}