题解:P17870 [FJCPC 2026] 变幻自在
题意
求
分析
对
当
当
实现
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL qmi(LL a,LL k,LL mod)
{
LL res = 1;
a %= mod;
while(k)
{
if(k & 1) res = res * a % mod;
k >>= 1;
a = a * a % mod;
}
return res;
}
int main()
{
int t;
cin>>t;
while(t --)
{
LL n,m;
cin>>n>>m;
if(n & 1) cout<<qmi(2,(n - 1) / 2 * (n - 2),m)<<'\n';
else cout<<qmi(2,(n - 2) / 2 * (n - 1) + 1,m)<<'\n';
}
return 0;
}