diff options
Diffstat (limited to '')
| -rw-r--r-- | 07_mathematics/exponentiation_1095.cpp | 19 |
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 | |||
| 3 | static constexpr unsigned long long MOD = 1000000007; | ||
| 4 | |||
| 5 | unsigned 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 | |||
| 12 | int 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 | } | ||
