Submission

Status:
[PPPPPPPPPPPPPPPPPPPP]

Score: 100

User: Dormon

Problemset: ยกกำลัง

Language: cpp

Time: 0.007 second

Submitted On: 2024-12-11 21:57:00

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <numeric>

#define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
const bool TEST_CASE = 1;

template<typename T>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* name, T value) {
    std::cout << name << " : " << value << '\n';
}

template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {
    for(auto &x : a) out << x << ' '; 
    return out;
};
template<typename T, typename... Args>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* names, T value, Args... args) {
    const char* comma = strchr(names, ',');
    std::cout.write(names, comma - names) << " : " << value << " | ";
    Debug(comma + 1, args...);
}
const int mod = 1e9+7;

int64_t mul(int64_t a, int64_t b){
    a %= mod, b %= mod;
    return (a*b) % mod;
}

int64_t bin_pow(int64_t b, int64_t n){
    if (n == 1)
        return b;
    int64_t res = bin_pow(b, n/2);
    if (n&1)
        return mul(mul(res, res), b);
    return mul(res, res);
}

void solve(){
    int64_t n, m;
    cin >> n >> m;
    cout << bin_pow(n, m) % mod << '\n';
}

int main()
{
    #ifndef DORMON
        ios_base::sync_with_stdio(0); 
    #endif
    cin.tie(0);
    int q = 1; 
    if (TEST_CASE) cin >> q;
    while (q--){
        solve();
    }
}