cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

exponentiation_ii_1712.cpp (509B)


      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     unsigned long long mod) {
      7 	if (b == 0) return 1;
      8 	if (a == 0) return 0;
      9 	if (b % 2 == 0) return pow(a*a % mod, b/2, mod) % mod;
     10 	return (a * pow(a, b-1, mod)) % mod;
     11 }
     12 
     13 int main() {
     14 	unsigned long long n, a, b, c;
     15 	std::cin >> n;
     16 	for (unsigned long long i = 0; i < n; i++) {
     17 		std::cin >> a >> b >> c;
     18 		std::cout << pow(a, pow(b, c, MOD-1), MOD) << "\n";
     19 	}
     20 }