求助
查看原帖
求助
354482
Ben幻影楼主2021/11/13 22:18

p3383

hack后发现数据非常硬

没有TLE

全WA

救救我吧

ORZ

#include<bits/stdc++.h>
const int N = 1e8*2+10;
using namespace std;

int n,m,tmp, Prime[N], cnt = 0;
bool isPrime[N];
void GetPrime(int n) {
    for (int i = 2; i <= n; i++) {
        if (isPrime[i])Prime[++cnt] = i;
        for (int j = 1; j <= cnt && Prime[j] * i <= n; j++) {
            isPrime[Prime[j] * i] = 0;
            if (i % Prime[j] == 0)break;//这一行保证所有合数只被筛去一次
        }
    }
}

int main() {
    cin>>n>>m;
    for (int i = 2; i <= n; i++)isPrime[i] = 1;
    GetPrime(n);
    for(int i=1;i<=m;i++){
    	cin>>tmp;
    	cout<<Prime[tmp]<<endl;
	}
	cout<<cnt<<endl;
    return 0;
}
2021/11/13 22:18
加载中...