跳到正文

休闲·娱乐

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

Lzy_4C约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年12月16日
收录
2026年7月30日
更新
2026年11月14日
篇幅
约 1 分钟

版本

  1. v1当前

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

代码:

C++
#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;
}

有大佬帮忙改改吗

原文