Main logic of Sundaram . Mark all numbers of the form i + j + 2 ij as true where 1 <= i <= j
for ( int i = 1 ; i <= nNew ; i ++ ) for ( int j = i ; ( i + j + 2 * i * j ) <= nNew ; j ++ ) marked [ i + j + 2 * i * j ] = true ;