输入格式 一行一个正整数 n,表示有 n 种商品,2≤n≤100000。
输出格式 一行若干个正整数,表示若干种商品编号且每个编号均为素数,请从小到大输出,每两个数之间有一个空格。
我的code
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int MAXN = 200010;
const int INF = 1;
const int mod = 1;
int n;
bool vis[MAXN];
int read(){
int s = 0, f = 0;
char ch = getchar();
while(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
while(isdigit(ch)) s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return f ? -s : s;
}
int main()
{
n = read();
for(int i = 2; i <= n; ++i){
if(!vis[i]){
printf("%d ", i);
vis[i] = true;
for(int j = i * i; j <= n; j += i) vis[j] = true;
}
}
return 0;
}
求指教