Iterate over all possible combinations of i , j , k for 60 bits . And add all the numbers with 0 , 1 or 2 set bits into the set allNum .
for ( int i = 0 ; i <= 60 ; i ++ ) { for ( int j = 0 ; j <= 60 ; j ++ ) { for ( int k = 0 ; k <= 60 ; k ++ ) {