1 #include <iostream>  
 2 #include <cstring>  
 3 using namespace std;  
 4         
 5 bool isPrime[1000000];  
 6 int prime[1000000];  
 7 int MAX, total, cnt;  
 8         
 9 void makePrime() {  
10     memset(isPrime,true,sizeof(isPrime));  
11     memset(prime,0,sizeof(prime));  
12     total = cnt = 0;  
13     for(int i = 2; i <= MAX; ++i) {  
14         if(isPrime[i]) prime[total++] = i;  
15         for(int j = 0; j < total && i*prime[j] <= MAX; ++j) {  
16             ++cnt;  
17             isPrime[i*prime[j]] = false;  
18 //i此时不是素数,只是拓展用  
19             if(i%prime[j] == 0) break;  
20         }  
21     }  
22 }  
23         
24 int main(){  
25     while(cin>>MAX){  
26         makePrime();  
27         cout<<total<<' '<<cnt<<endl;  
28         //for(int i = 0; i < total; ++i) cout<<prime[i]<<endl;  
29     }  
30 }
View Code

相关文章:

  • 2022-01-10
  • 2021-08-13
  • 2021-08-07
  • 2021-07-04
猜你喜欢
  • 2020-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-04
相关资源
相似解决方案