#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
int i, j, n1, s[50001] = {};
double n;
for (i = 2; i <= 50000; i++)
{
s[i] = 1;
}
n = sqrt(50000);
for (i = 2; i <= n; i++)
{
if (s[i] == 0)
continue;
for (j = 2 * i; j <= 50000; j += i)
{
s[j] = 0;
n1++;
}
}
for (i = 2; i <= 50000; i++)
{
if (s[i] == 1)
cout << i << " ";
}
cout << endl;
cout << "共" << n1 << "个质数" << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
我的比吴子睿522快。
