utility function to count the number of set bits
static int setBits ( int n ) { return Integer . bitCount ( n ) ; } public static int log2 ( int x ) { return ( int ) ( Math . log ( x ) / Math . log ( 2 ) + 1e-10 ) ; }