aboutsummaryrefslogtreecommitdiff
path: root/07_mathematics/exponentiation_1095.cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
commit96254947699986c59f0dc63d69fd4b76bd3ed43e (patch)
tree6c4dca945d7f7427c48be234d827fe4d33be02c5 /07_mathematics/exponentiation_1095.cpp
downloadcses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz
cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip
Initial commit
Diffstat (limited to '07_mathematics/exponentiation_1095.cpp')
-rw-r--r--07_mathematics/exponentiation_1095.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/07_mathematics/exponentiation_1095.cpp b/07_mathematics/exponentiation_1095.cpp
new file mode 100644
index 0000000..1ba8509
--- /dev/null
+++ b/07_mathematics/exponentiation_1095.cpp
@@ -0,0 +1,19 @@
1#include <iostream>
2
3static constexpr unsigned long long MOD = 1000000007;
4
5unsigned long long pow(unsigned long long a, unsigned long long b) {
6 if (b == 0) return 1;
7 if (a == 0) return 0;
8 if (b % 2 == 0) return pow(a*a % MOD, b/2) % MOD;
9 return (a * pow(a, b-1)) % MOD;
10}
11
12int main() {
13 unsigned long long n, a, b;
14 std::cin >> n;
15 for (unsigned long long i = 0; i < n; i++) {
16 std::cin >> a >> b;
17 std::cout << pow(a, b) << "\n";
18 }
19}

Generated with cgit - Back to sebastiano.tronto.net