Java program for the above approach
import java . util . HashMap ; import java . io . * ; class GFG { static int log2 ( int N ) { int result = ( int ) ( Math . log ( N ) / Math . log ( 2 ) ) ; return result ; }