首页 > 代码库 > Delete_The _Selected_Prime

Delete_The _Selected_Prime

 1 #include <iostream> 2 #include <cmath> 3 #define N 99999 4  5 using namespace std; 6  7 bool flag[N]; 8  9 void prime()10 {11     for (int i = 2; i < N; i++)12     {13         if (i % 2 == 0)14         {15             flag[i] = false;16         }17         else18         {19             flag[i] = true;20         }21     }22     for (int i = 3; i < sqrt(N); i+= 2)23     {24         if (flag[i])25         {26             for (int j = i + i; j < N; j+= i)27             {28                 flag[j] = false;29             }30         }31     }32 33     for (int i = 2; i < 100; i++)34     {35         if (flag[i])36         {37             cout << i << endl;38         }39     }40 }41 42 int main()43 {44     prime();45     return 0;46 }

 

Delete_The _Selected_Prime