比赛 2025暑期集训第2场 评测结果 AAAAAAAAAA
题目名称 整数合并 最终得分 100
用户昵称 秋_Water 运行时间 0.036 s
代码语言 C++ 内存使用 3.80 MiB
提交时间 2025-06-29 16:06:11
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int f[100010],a,b,p,ans;
bool np[100010];
int find(int x){
	if(f[x]!=x)return f[x]=find(f[x]);
	else return x; 
}
int main(){
	freopen("setb.in","r",stdin);
	freopen("setb.out","w",stdout); 
	cin>>a>>b>>p;
	ans=b-a+1; 
	for (int i=a;i<=b;++i){
		f[i]=i;
	}
	
	for (int i=2;i<=b;++i){
		if (!np[i]){
			if (i>=p){
				for (int j=i*2;j<=b;j+=i){
					np[j]=true;
					if (j-i>=a&&find(j)!=find(j-i)){
						f[find(j)]=find(j-i);
						--ans;
					}
				}
			}
			else{
				for (int j=i*2;j<=b;j+=i){
					np[j]=true;
				}
			}
		}
	}
	cout<<ans;
	
	return 0;
}