Finding all numbers having factor power of 2 and 3 Using sieve
bool arr [ n + 1 ] ; memset ( arr , false , sizeof arr ) ; int two = 1 , three = 1 ; while ( two + 1 < n ) { arr [ two ] = true ; while ( two * three + 1 < n ) { arr [ three ] = true ; arr [ two * three ] = true ; three *= 3 ; } three = 1 ; two *= 2 ; }