From f181319300d2731da64659a35272b834b57ee0df Mon Sep 17 00:00:00 2001 From: Alfredo Beaumont Date: Mon, 5 Aug 2019 19:49:03 +0200 Subject: [PATCH] [cses] Add C++ solution for 1712 - Exponentiation II. --- cses/1712-1.ans | 3 +++ cses/1712-1.in | 4 ++++ cses/1712.cc | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 cses/1712-1.ans create mode 100644 cses/1712-1.in create mode 100644 cses/1712.cc diff --git a/cses/1712-1.ans b/cses/1712-1.ans new file mode 100644 index 00000000..c6999624 --- /dev/null +++ b/cses/1712-1.ans @@ -0,0 +1,3 @@ +2187 +50625 +763327764 diff --git a/cses/1712-1.in b/cses/1712-1.in new file mode 100644 index 00000000..823bc099 --- /dev/null +++ b/cses/1712-1.in @@ -0,0 +1,4 @@ +3 +3 7 1 +15 2 2 +3 4 5 diff --git a/cses/1712.cc b/cses/1712.cc new file mode 100644 index 00000000..4b8aae9a --- /dev/null +++ b/cses/1712.cc @@ -0,0 +1,27 @@ +// https://cses.fi/problemset/task/1712/ +#include + +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; + } +}