RE求助
查看原帖
RE求助
147401
koishi_offical楼主2021/11/21 20:09

为什么全部RE了啊啊啊啊啊啊啊

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+10;
int n=4e5;
int T;
int p[N],cnt;
bool v[N],f[N];
int r[N];
int read()
  {
  	char ch=getchar();
  	int f=0;
  	while(ch<'0'||ch>'9') ch=getchar();
  	while(ch>='0'&&ch<='9')
  	  {
  	  	f=f*10+ch-'0';
  	  	ch=getchar();
  	  }
  	return f;
  }
bool check(int x)
 {
 	  int a=x;
 	  while(a)
 	  	{
 	  	  int t=a%10;
 	  	  if(t==7) return 0;
 	      a/=10;
 	    }
 	  for(int i=1;p[i]*p[i]<=x;i++)
 	  	if(x%p[i]==0)
 	  	  {
 	  	    if(!f[x/p[i]]||!f[p[i]]) return 0;
 	  	  }
 	  return 1;
 }
void init()
  {
  	for(int i=2;i<=n;i++)
  	  {
  	  	if(!v[i]) p[++cnt]=i;
  	  	for(int j=1;p[j]*i<=n;j++)
  	  	  {
  	  	  	v[p[j]*i]=1;
  	  	  }
  	  }
  	f[1]=1;
  	int l=1;
  	for(int i=2;i<=n;i++)
  	  if(check(i)) 
		  {
		    f[i]=1;
		    r[l]=i;
		    l=i;
	      }
  	  else f[i]=0;
  }
int main() {
	//freopen("number.in","r",stdin);
	//freopen("number.out","w",stdout);
	cin>>T;
    init();
    //cout<<v[91]<<" "<<f[72]<<" "<<f[107]<<" "<<f[95];
    while(T--)
      {
      	int x=read();
      	if(!f[x]) cout<<-1<<endl;
      	else cout<<r[x]<<endl;
      }
	return 0;
}
2021/11/21 20:09
加载中...