#include<iostream>
#include<string.h>
#define KEY 10000
using namespace std;
int count = 0;
int prime[KEY];//保存 素数的数组
int check[KEY];//是素数为1 不是素数为0
//下面函数 的工作 将输入数据的素数存入数组内
void fun(int max) ;
int main()
{
memset(check,0,sizeof(check));
int max;
cin >> max;
fun(max);
for(int i = 0; i< count;i++)
cout << prime[i] << endl;
}
void fun(int max)
{
for(int i = 2;i < max;i++)//表示要数的当前数字
{
if(!check[i]) //当前数字为质素放入质素数组钟
prime[count++] = i; //0是质素 去掉所有的质素的倍数 为1
for(int j = 2;j*prime[count-1]< max;j++) //将质数数组中的 shu
{
check[j*prime[count-1]] = 1;
}
}
}
网友评论