有必要请各位分析时间复杂度
  • 板块灌水区
  • 楼主王烨
  • 当前回复14
  • 已保存回复14
  • 发布时间2021/11/29 22:47
  • 上次更新2023/11/3 23:14:55
查看原帖
有必要请各位分析时间复杂度
207671
王烨楼主2021/11/29 22:47
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
bool num[N];
int a[N],h[N],low[N];
int main()
{
	int k=0;
	for(int i=1;i<=7;i++)
	{
		int x=7*pow(10,i-1);
		while(x<1e7)
		{
			a[++k]=x;
			num[x]=true;
			for(int j=1;j<pow(10,i-1);j++)
			{
				int p=x+j;
				a[++k]=p;
				num[p]=true;
			}
			x+=pow(10,i);
		}
	}
	sort(a+1,a+k+1);
	for(int i=1;i<=k;i++)
	   for(int j=1;j<=N/a[i];j++) num[a[i]*j]=true;
	for(int i=1,j=0;i<=10000000;i++)
	{
		while(!num[i])
		{
			j++;
			low[i]=j;
			h[low[i]]=i;
			i++;
		}
	}
	int t;
	cin>>t;
	while(t--){
		int m;
		cin>>m;
		if(num[m]){
			cout<<-1<<endl;
			continue;
		}
		else cout<<h[low[m]+1]<<endl;
	}
	return 0;
}
2021/11/29 22:47
加载中...