样例全过,洛谷10',求指导
查看原帖
样例全过,洛谷10',求指导
557826
D_guard楼主2021/11/23 18:29

洛谷里#1AC,#2-7均WA,求助!(先不考虑时间,把思路理顺再说...) 代码如下:

#include <iostream>
using namespace std;
#define ll long long
int num[10000012];

bool sev(ll x)
{
	while(x>0)
	{
		if(x%10==7)
			return 1;
		x/=10;
	}
	return 0;
}

int main()
{
	ll t,x,p=0;
	cin>>t;
	for(ll i=1;i<=t;i++)
	{
		cin>>x;
		if(p<=x)
		{
			for(int j=7;j<=p;j++)
			{
				if(num[j]==2)
					for(int k=p/j+1;k*j<=x+11;k++)
						num[k*j]=1;
			}
			while(p<=x+11)
			{
				p++;
				if(num[t])	continue;
				if(sev(p))
				{
					num[p]=2;
					for(int j=2;p*j<=x+11;j++)
						num[p*j]=1;
				}
			}
		}
		if(num[x])
			cout<<-1<<endl;
		else
		{
			x+=1;
			while(num[x])
				x++;
			cout<<x<<endl;
		}
	}
	return 0;
}
2021/11/23 18:29
加载中...