为啥全RE了
查看原帖
为啥全RE了
217786
创新人士楼主2021/11/20 18:17
#include<bits/stdc++.h>
using namespace std;
#define N 300005
int T;
inline int read()
{
	int s=0,w=1;char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')w=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		s=s*10+ch-'0';ch=getchar();
	}
	return s*w;
}
inline void print(int x)
{
	if(x<0)
	{
		putchar('-');print(-x);return ;
	}
	if(x<10)
	{
		putchar('0'+x);return ;
	}
	print(x/10);print(x%10);
	return;
}
int ip[2*N],pr[2*N],cnt;
inline bool ck(int x)
{
	if(ip[x])return 1;
	while(x)
	{
		if(x%10==7)return 1;
		x/=10;
	}
	return 0;
}
int pt[2*N],tot;
void init()
{
	for(int i=1;i<=N-5;i++)
	{
		for(int j=1;j*j<=i;j++)
		{
			if(i%j!=0)continue;
			if(ck(i/j)||ck(j))
			{
				ip[i]=1;pr[++cnt]=i;
			}
		}
		if(!ip[i]&&ck(i))
		{
			pr[++cnt]=i;ip[i]=1;
		}
		if(!ip[i])
		{
			
			pt[++tot]=i;
		}
	//	if(ip[i])cout<<i<<endl;
	}
}
void solve()
{
	cin>>T;
	while(T--)
	{
		int x;
		cin>>x;
		if(ip[x])
		print(-1);
		else
		{
			int l=1,r=tot;
			while(l!=r)
			{
				int mid=(l+r)/2;
				if(pt[mid]<=x)
				{
					l=mid+1;
				}
				else
				r=mid;
				
			}
			print(pt[l]);
		}
		putchar('\n');
	}
}
signed main()
{
//	freopen("number.in","r",stdin);
//	freopen("number.out","w",stdout);
	init();
	solve();
	return 0; 
}
2021/11/20 18:17
加载中...