上次考级栽在这题上了,来luogu发个题解: ),希望大家不要被这题难住,说实话这题真的有点超纲了,但在官方狡辩下,这题还是出出来了,而且还被我碰上了,运气绝对大凶!!!
#include <bits/stdc++.h>
using namespace std;
int a,p;
int ans;
int fpw(int b,int e)
{
if (e==0) return 1;
int r=fpw(b,e>>1);
r=1ll*r*r%p;
if (e&1) r=1ll*r*b%p;
return r;
}
void check(int e)
{
if (fpw(a,e)==1) ans=0;
}
int main()
{
int t;
cin >> t;
while (t--)
{
cin >> a >> p;
ans=1;
int phi=p-1,r=phi;
for (int i=2;i*i<=phi;i++)
{
if (phi%i==0)
{
check(phi/i);
while (r%i==0) r/=i;
}
}
if (r>1) check(phi/r);
if (ans) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}