Loading

P5535 【XR-3】小道消息 - 数论

题解

根据切比雪夫定理,对于整数 \(x>1\),至少有一个质数 \(p\) 满足 \(x<p<2x\)

所以第一天会从数字为 \(k+1\) 的人传到某个满足 \(\lfloor \frac{n}{2} \rfloor<p<n\) 的质数 \(p\),第二天会从这个质数传到所有数。

考虑什么情况下只需要一天:\(2\sim (n+1)\) 中所有数(除了 \(k+1\))都与 \(k+1\) 互质,即 \(k+1\) 为质数且 \(2(k+1)>n+1\)

一个更强的说法:对于任意整数 \(n>3\),都有质数 \(p\) 满足 \(n<p<2n-2\)

代码
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;
#define For(Ti,Ta,Tb) for(int Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(int Ti=(Ta);Ti>=(Tb);--Ti)
template<typename T> void Read(T &x){
	x=0;int _f=1;
	char ch=getchar();
	while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	x=x*_f;
}
template<typename T,typename... Args> void Read(T &x,Args& ...others){
	Read(x);Read(others...);
}
typedef long long ll;
const int Inf=0x3f3f3f3f;
ll n,k;
bool IsPrime(ll x){
	for(ll i=2;i*i<=x;++i) if(x%i==0) return 0;
	return 1;
}
int main(){
	Read(n,k);
	puts(IsPrime(k+1)&&(k+1)*2>n+1?"1":"2");
	return 0;
}
posted @ 2021-06-28 20:25  Alan_Zhao_2007  阅读(48)  评论(0编辑  收藏  举报