Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main( String[] args )
- {
- int limit = 2000000;
- boolean[] primes = new boolean[( limit + 1 )];
- primes[0] = false;
- primes[1] = false;
- for ( int x = 2; x < ( limit + 1 ); x++ )
- {
- primes[x] = true;
- }
- long sum = 0;
- int x = 3;
- for ( int index = 2; ( index * index ) <= limit; index++ )
- {
- while ( !primes[index] )
- {
- index++;
- }
- x = index * ( index - 1 );
- if ( x <= limit - index )
- {
- x = x + index;
- primes[x] = false;
- System.out.println( "marking " + x + " as false" );
- }
- }
- for ( int index = 2; index < limit; index++ )
- {
- while ( !primes[index] )
- {
- index++;
- if ( index == limit )
- {
- break;
- }
- }
- sum = sum + index;
- System.out.println( "adding " + index + '\t' + "current sum is "
- + sum );
- }
- sum = sum - limit;
- System.out.println("subtracting the limit");
- System.out.println( "The sum is " + sum );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement