TLE怎么回事!!!
查看原帖
TLE怎么回事!!!
954973
jyz2012楼主2023/5/9 22:24
#include <iostream>
using namespace std;
bool isPrime(int n){
	if(n==1)return false;
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}
int main(){
	int n,m;
	cin>>n>>m;
	int ans=0;
//	int ans[n+1]={};
	int l,r;
	for(int i=1;i<=n;i++){
		cin>>l>>r;
		if(r>m or l<1){
			cout<<"Crossing the line"<<endl;
			continue;
		}
		for(int j=l;j<=r;j++){
			if(isPrime(j)){
				ans++;
			}
		}
		cout<<ans<<endl;
      ans=0;
	}
	return 0;
}
2023/5/9 22:24
加载中...