由于发在题目里的帖子没人回,来这试试

· · 休闲·娱乐

题目传送站:https://www.luogu.com.cn/problem/P11961

代码:

#include<bits/stdc++.h>
#define N 100860 
using namespace std;
//const int N=1e5+1;
int t,p,a;
bool yuan_gan(int x,int y){
    if(x>=y) return false;
    int ls=1;
    for(int i=1;i<y;i++){
        ls%=y;
        ls*=x;
    }
    if(ls%y!=1) return false;
    for(int i=1;i<p-1;i++){
        int ly=1;
        for(int j=1;j<=i;j++){
            ly%=y;
            ly*=x;
        }
        if(ly%y==1) return false;
    }
    return true;
}
int main(){
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>a>>p;
        if(yuan_gan(a,p)) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

有大佬帮忙改改吗