欧拉筛RE求调
  • 板块灌水区
  • 楼主精神小伙!
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/4/27 10:43
  • 上次更新2024/4/27 12:44:25
查看原帖
欧拉筛RE求调
304211
精神小伙!楼主2024/4/27 10:43

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;//unsigned
const int maxn=1e8+5;
int n,cnt,T;
int a[maxn];
bool vis[maxn];
void prime(int x)
{
	for(int i=2;i<=x;++i)
    {
    	if(!vis[i]) a[++cnt]=i;
    	for(int j=1;a[j]<=sqrt(x);++j)
    	{
    		vis[a[j]*i]=1;
			if(i%a[j]==0) break;
		}
	}
}
int main()
{
    std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>T>>n;
	prime(T);
	for(int i=1;i<=n;++i)
	{
		int x;
		cin>>x;
		cout<<a[x]<<endl;
	}
	return 0;
}

2024/4/27 10:43
加载中...