![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cmath> 3 utilisant l' espace de noms std; 4 5 const int MAXN = 100000000 ; 6 int a [MAXN]; 7 bool isprime ( int x); 8 int main () { 9 int n, count = 0 ; 10 pour ( int i = 2 ; i <MAXN; i ++ ) { 11 if (isprime (i) == true ) { 12 a [i] = 1; 13 unités ++ ; 14 if (count == 10000 ) printf ( " i:% d \ n " , i); 15 } 16 } 17 18 19 20 scanf ( " % d " , & n); 21 renvoie 0 ; 22 } 23 24 bool isprime ( int x) { 25 if (x == 1 ) return false ; 26 si (x == 2) retourne vrai ; 27 for ( int i = 2 ; i <= sqrt (( double ) x) + 1 ; i ++ ) { 28 if (x% i == 0 ) return false ; 29 30 } 31 return true ; 32 }
Donc, à 104729, il y a 10 000 nombres premiers.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cmath> 3 utilisant l' espace de noms std; 4 const int MAXN = 10001 ; 5 int p [MAXN], m, n; 6 bool isprime ( int x); 7 void init (); 8 accord nul (); 9 int main () { 10 init (); 11 scanf ( " % d% d " , & m, & n); 12 deal (); 13 renvoie 0 ; 14 } 15 bool isprime ( int x) { 16 if (x == 1 ) return false ; 17 else if (x == 2 ) return true ; 18 19 for ( int i = 2 ; i <= sqrt (( double ) x) + 1 ; i ++ ) { 20 if (x% i == 0 ) return false ; 21 } 22 return true ; 23 } 24 void init () { 25 int count = 1 ; 26 pour ( int i = 2 ; i < 10000000 ; i ++ ) { 27 if (isprime (i)) { 28 p [count ++] = i; 29 si (count == 10001 ) casse ; 30 } 31 } 32 } 33 void deal () { 34 for ( int i = m; i <= n; i ++ ) { 35 printf ( "% d " , p [i]); 36 if (i! = n && (i-m + 1 )% 10 ! = 0 ) printf ( " " ); 37 else printf ( " \ n " ); 38 } 39 }