First number to leave an odd remainder after repetitive division by 2 | Python3 program to implement the above 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
from math import log NEW_LINE def getFirstSetBitPos ( n ) : NEW_LINE INDENT return log ( n & - n , 2 ) + 1 NEW_LINE DEDENT def oddFirst ( a , b ) : NEW_LINE INDENT steps_a = getFirstSetBitPos ( a ) NEW_LINE steps_b = getFirstSetBitPos ( b ) NEW_LINE if ( steps_a == steps_b ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ( steps_a > steps_b ) : NEW_LINE INDENT return b NEW_LINE DEDENT if ( steps_a < steps_b ) : NEW_LINE INDENT return a NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 10 NEW_LINE b = 8 NEW_LINE print ( oddFirst ( a , b ) ) NEW_LINE DEDENT