Skip to content

Commit

Permalink
[cses] Add C++ solution for 1712 - Exponentiation II.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeaumont committed Aug 5, 2019
1 parent 438028a commit f181319
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cses/1712-1.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2187
50625
763327764
4 changes: 4 additions & 0 deletions cses/1712-1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
3 7 1
15 2 2
3 4 5
27 changes: 27 additions & 0 deletions cses/1712.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// https://cses.fi/problemset/task/1712/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll M = 1000000007;

ll pow(ll a, ll b, ll m) {
ll r = 1, e = a;
while (b) {
if (b & 1) (r *= e) %= m;
(e *= e) %= m;
b >>= 1;
}
return r;
}

int main() {
ll n, a, b, c;
cin >> n;
while (n--) {
cin >> a >> b >> c;
ll x = pow(b, c, M - 1);
cout << pow(a, x, M) << endl;
}
}

0 comments on commit f181319

Please sign in to comment.