Skip to content

Commit eb4e7aa

Browse files
committed
UVA 1230 Binary Exponentation
1 parent 3f9998c commit eb4e7aa

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

UVA/1230.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define llong long long
4+
llong x, y, n;
5+
llong solve() {
6+
llong res = 1 % n;
7+
while (y > 0) {
8+
if (y & 1)
9+
res = res * x % n;
10+
x = x * x % n;
11+
y >>= 1;
12+
}
13+
return res;
14+
}
15+
int main(void) {
16+
int NTEST = 0;
17+
cin >> NTEST;
18+
for(; NTEST; NTEST--) {
19+
cin >> x >> y >> n;
20+
llong ans = solve();
21+
cout << ans << '\n';
22+
}
23+
int END;
24+
cin >> END;
25+
}

0 commit comments

Comments
 (0)