Submission
Status:
[PPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: qweqwe
Problemset: ยกกำลัง
Language: cpp
Time: 0.006 second
Submitted On: 2025-10-14 19:07:22
#include <bits/stdc++.h>
#define speed cin.tie(0)->sync_with_stdio(0)
#define ll long long
#define pii pair<int,int>
#define MOD 1000000007
using namespace std;
int main(){
speed;
ll t;cin >> t;
for (int i=0;i<t;i++){
ll n,m;cin >> n >> m;
ll temp=0;
for (int j=0;j<m;j++){
if ((1<<j)>m){
temp=j;break;
}
}//cout << temp << " ";
vector<ll> dp(temp+1);dp[0]=1;dp[1]=n;
for (int j=2;j<=temp;j++){
dp[j]=(dp[j-1]*dp[j-1])%MOD;
}ll r=m-(1<<(temp-1));int idx=1;
ll sep=1;
while (r>0){
ll t=r%2;r/=2;
//cout << t << " ";
if (t) sep*=dp[idx];sep%=MOD;
idx++;
}ll final=(dp[temp]*sep)%MOD;cout << final << "\n";
/*
for (int i:dp){
cout << i << " ";
}cout << "\n";
*/
}
return 0;
}