66分求条
查看原帖
66分求条
965292
3Luby3楼主2024/8/27 11:44

代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,l,r,s[1000001];
bool vis[1000001];
void init(int m){
	for(int i=2;i<=m;i++){
		if(vis[i]==0){
			for(int j=2*i;j<=m;j+=i) vis[j]=1;
		}
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	init(m);
	for(int i=1;i<=m;i++){
		if(vis[i]==1){
			s[i]=s[i-1];
		}else{
			s[i]=s[i-1]+1;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>l>>r;
		if(l<1 || r>m) cout<<"Crossing the line\n";
		else cout<<s[r]-s[l-1]<<endl;
	}
	return 0;
}

悬关

2024/8/27 11:44
加载中...