Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std ;
- int N = 1000000000 ;
- int status[ (1000000000>>5)+2 ] ;
- bool CHECK( int n , int pos ) {
- return (bool)( n & ( 1 << pos ) ) ;
- }
- int SET( int n , int pos ) {
- return n = n | ( 1 << pos ) ;
- }
- void sieve( void ) {
- int i , j , sqrt_N ;
- sqrt_N = sqrt((double)N) ;
- for( i = 3 ; i <= sqrt_N ; i += 2 ) {
- if( CHECK( status[i>>5] , i & 31 ) == 0 ) {
- for( j = i*i ; j <= N ; j += ( i << 1 ) ) {
- status[j>>5] = SET( status[j>>5] , j & 31 ) ;
- }
- }
- }
- }
- int main()
- {
- sieve() ;
- int gona = 1 , flag = 501 ;
- printf("2\n") ;
- for( int i = 3 ; i <= N ; i += 2 ) {
- if( CHECK( status[i>>5] , i & 31 ) == 0 ) {
- gona++ ;
- }
- if( gona == flag ) {
- flag = flag + 500 ;
- printf("%d\n",i) ;
- }
- }
- return 0 ;
- }
Add Comment
Please, Sign In to add comment