First number to leave an odd remainder after repetitive division by 2 | Java program implementation of the approach ; Function to return the position least significant set bit ; Function return the first number to be converted to an odd integer ; Stores the positions of the first set bit ; If both are same ; If A has the least significant set bit ; Otherwise ; Driver code
import java . util . * ; import java . lang . Math ; import java . io . * ; class GFG { static int getFirstSetBitPos ( int n ) { return ( int ) ( Math . log ( n & - n ) / Math . log ( 2 ) ) ; } static int oddFirst ( int a , int b ) { int steps_a = getFirstSetBitPos ( a ) ; int steps_b = getFirstSetBitPos ( b ) ; if ( steps_a == steps_b ) { return - 1 ; } else if ( steps_a > steps_b ) { return b ; } else { return a ; } } public static void main ( String [ ] args ) { int a = 10 ; int b = 8 ; System . out . print ( oddFirst ( a , b ) ) ; } }