Submission

Status:
[PPPPPPPPPPPPPPPPPPPP]

Score: 100

User: Asphyrv

Problemset: ยกกำลัง

Language: cpp

Time: 0.006 second

Submitted On: 2024-10-18 00:45:46

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll power(ll a, ll n, ll mod){
    ll ans = 1;
    while(n > 0){
        if(n % 2 == 1){
            ans *= a;
        }
        n >>= 1;
        a *= a;
        a %= mod;
        ans %= mod;
    }
    return ans % mod;
}

int main(){
    cin.tie(NULL)->ios_base::sync_with_stdio(false);
    ll n, m, t;
    cin >> t;
    while(t--){
        cin >> n >> m;
        cout << power(n, m, 1000000007) << '\n';
    }

    return 0;
}