社区讨论

奇怪的全TLE

P7588双重素数(2021 CoE-II A)参与者 2已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@m1555c1v
此快照首次捕获于
2024/09/16 23:09
去年
此快照最后确认于
2025/11/04 21:04
4 个月前
查看原帖
CPP
#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;
}
这段代码的提交结果
CPP
#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;
}
这段代码的提交结果

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

CPP
#define ll long long

改成了

CPP
#define int long long

为什么会TLE而不是MLE啊

回复

6 条回复,欢迎继续交流。

正在加载回复...