下载的数据过了,但爆零了
查看原帖
下载的数据过了,但爆零了
307826
Lamorak楼主2021/7/20 15:43
rt

数据都过了,依旧爆零

我下载的是假数据 ?

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+91;
ll ans1,r,cnt[N],l,ans,n,m;
bool vis[N],p[N];

inline ll read(){
	ll x=0,f=1;char s=getchar();
	while(s<'0'||s>'9'){if(s='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	return x*f;
}

signed main(){
	for(ll i=2;i<=50000;i++){
		if(!p[i]) cnt[++ans]=i;
		for(ll j=1;j<=ans&&cnt[j]<=50000/i;j++){
			p[i*cnt[j]]=1;
			if(i%cnt[j]==0) break;
		}
	}
	n=read();m=read();
	while(n--){
		l=read();r=read();
		if(r>m||l<1){printf("Crossing the line\n");continue;}
		if(l==1) l=2;
		memset(vis,0,sizeof(vis));
		ans1=0;
		for(ll i=1;i<=ans;i++){
			ll p=cnt[i];
			ll s=max((l+p-1)/p*p,2*p);
			for(ll j=s;j<=r;j+=p) vis[j-l+1]=1;
		}
		for(ll i=1;i<=r-l+1;i++) if(vis[i]==0) ans1++;
		printf("%lld\n",ans1);
	}
	return 0;
}

数据一:

10 10
-6 6
1 9
-2 11
4 11
-2 10
-8 17
2 7
-2 5
2 8
-3 6
Crossing the line
4
Crossing the line
Crossing the line
Crossing the line
Crossing the line
4
Crossing the line
4
Crossing the line
2021/7/20 15:43
加载中...