Main logic of Sundaram . Mark all numbers which do not generate prime number by doing 2 * i + 1
for ( $ i = 1 ; $ i <= ( ( int ) sqrt ( $ MAX ) - 1 ) / 2 ; $ i ++ ) for ( $ j = ( $ i * ( $ i + 1 ) ) << 1 ; $ j <= ( int ) ( $ MAX / 2 ) ; $ j = $ j + 2 * $ i + 1 ) $ marked [ $ j ] = true ;