1 solutions

  • 0
    @ 2025-5-6 15:56:57

    40pts 直接根据题目要求枚举即可

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    int main()
    {
    	int T;
    	cin>>T; 
    	while(T--)
    	{
    		LL a,p;
    		cin>>a>>p;
    		if(a<1||a>=p)
    		{
    			cout<<"No"<<endl;
    			continue;
    		}
    		LL x=1;
    		for(int i=1;i<p;i++)
    		{
    			x=x*a%p;
    		}
    		if(x!=1)
    		{
    			cout<<"No"<<endl;
    			continue;
    		}
    		x=1;
    		int cnt=0;
    		for(int j=1;j<p-1;j++)
    		{
    			x=x*a;
    			x=x%p;
    			if(x==1)
    			{
    				cnt++;
    			}
    		}
    		if(cnt)
    		{
    			cout<<"No"<<endl;
    			continue;
    		}
    		cout<<"Yes"<<endl;
    	}
    	return 0;
    } 
    
    • 1

    Information

    ID
    2568
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    1
    Uploaded By