1 #include<iostream> 2 #include<cstring> 3 4 #define MAX_N 10000000 5 6 using namespace std; 7 8 bool flag[MAX_N]; 9 int prime[MAX_N]; 10 11 void solve() 12 { 13 memset(flag,1,sizeof(flag)); 14 flag[1] = 0; 15 int con=0; 16 for(int i = 2; i < MAX_N; i++) 17 { 18 if(flag[i]) 19 { 20 prime[con++] = i; 21 for(int j = 2*i; j < MAX_N; j+=i) 22 flag[j] = 0; 23 } 24 } 25 } 26 int main() 27 { 28 solve(); 29 return 0; 30 }
时间: 2024-10-24 07:10:03