#include<iostream>
using namespace std;
#define M 1000000
bool mark[M];
void sv(int n)
{
int i, j;
for(i=2;i*i<=n;i++)
{
if(mark[i] == false)
{
for(j=i+i;j<=n;j+=i)
{
mark[j] = true;
}
}
}
cout << endl;
for(i=2;i<=n;i++)
{
if(mark[i] == false)
{
cout << i << " ";
}
}
cout << endl;
}
int main()
{
int m;
cin >> m;
sv(m);
return 0;
}
using namespace std;
#define M 1000000
bool mark[M];
void sv(int n)
{
int i, j;
for(i=2;i*i<=n;i++)
{
if(mark[i] == false)
{
for(j=i+i;j<=n;j+=i)
{
mark[j] = true;
}
}
}
cout << endl;
for(i=2;i<=n;i++)
{
if(mark[i] == false)
{
cout << i << " ";
}
}
cout << endl;
}
int main()
{
int m;
cin >> m;
sv(m);
return 0;
}
Comments
Post a Comment