Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Nuttykub

Problemset: ยกกำลัง

Language: cpp

Time: 0.023 second

Submitted On: 2026-10-04 10:51:50

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

const ll mod=1e9+7;

ll power(ll a,ll b){ //หา a^b
    if(b==0)return 1;
    ll ans=power(a,b/2); //หา a^(b/2)
    ans*=ans; //a^(b/2) * a^(b/2) = a^b
    ans%=mod;
    if(b%2==1){
        ans*=a;
    }
    return ans%mod;
}

int main(){
    ll n;
    cin >> n;
    while(n--){
        ll a,b;
        cin >> a >> b;
        cout << power(a,b) << endl;
    }
    return 0;
}