大佬求助!!!
查看原帖
大佬求助!!!
1121518
StarsIntoSea楼主2023/10/2 16:08

洛谷上是对的 为什么在一本通网站(http://ybt.ssoier.cn:8088/problem_show.php?pid=2082) 就会超时啊??? 求助

#include <iostream>
#include <cstring>
using namespace std;

const int N=1e7+100;
bool  a[N];
int b[N];

void fin(int i){
	int t=i;
	while (t <= 1e7){
		a[t]=true;
		t+=i;
	}
}

bool sol(int t){
	while(t){
		if(t%10 == 7) return true;
		t/=10; 
	}
	return false;
}

int main(){
	//memset(a,1,sizeof(a));
	ios::sync_with_stdio(false);
	int lop=1;
	for(int i=2 ; i<=1e7+1 ;++i){
		if(!a[i]){
			if(sol(i)) fin(i);
			else{
				b[lop]=i;
				lop=i;
			}
		}
	}
	 
	int t;
	cin>>t;
	while(t--){
		int p;
		cin>>p;
		if(a[p]) cout<<"-1"<<endl;
		else cout<<b[p]<<endl;
	} 

}
2023/10/2 16:08
加载中...