奇怪的全TLE
查看原帖
奇怪的全TLE
1271070
Wh1spers0fTheW1nd楼主2024/9/16 23:08
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e8+5;
int pri[5761460],tot;
bitset<N> vis; 
void pre(){
    for(int i=2;i<=N;i++){
        if(!vis[i])	pri[++tot]=i;
        for(int j=1;j<=tot;j++){
            if(pri[j]*i>N) break;
            vis[pri[j]*i]=1;
            if(i%pri[j]==0) break;
        }
    }
}
bool check(int x) {
    int res=0;
    while(x){res+=x%10;x/=10;}
    return !vis[res];
}
signed main(){
	vis[0]=1;
	vis[1]=1;
	pre();
	int t,l,r;
	cin>>t;
	while(t--){
		int ans=0;
		cin>>l>>r;
		for(int i=l;i<=r;i++)if(!vis[i] && check(i))ans++;
		cout<<ans<<"\n";
	}
	return 0;
}

这段代码的提交结果

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e8+5;
int pri[5761460],tot;
bitset<N> vis; 
void pre(){
    for(int i=2;i<=N;i++){
        if(!vis[i])	pri[++tot]=i;
        for(int j=1;j<=tot;j++){
            if(pri[j]*i>N) break;
            vis[pri[j]*i]=1;
            if(i%pri[j]==0) break;
        }
    }
}
bool check(int x) {
    int res=0;
    while(x){res+=x%10;x/=10;}
    return !vis[res];
}
signed main(){
	vis[0]=1;
	vis[1]=1;
	pre();
	int t,l,r;
	cin>>t;
	while(t--){
		int ans=0;
		cin>>l>>r;
		for(int i=l;i<=r;i++)if(!vis[i] && check(i))ans++;
		cout<<ans<<"\n";
	}
	return 0;
}

这段代码的提交结果

这两段代码就是将第二行的

#define ll long long

改成了

#define int long long

为什么会TLE而不是MLE啊

2024/9/16 23:08
加载中...