Minimum division by 10 and multiplication by 2 required to reduce given number to 1 | Function to find the minimum number operations required to reduce N to 1 ; Stores count of powers of 2 and 5 ; Calculating the primefactors 2 ; Calculating the primefactors 5 ; If n is 1 and cnt2 <= cnt5 ; Return the minimum operations ; Otherwise , n can 't be reduced ; Driver Code ; Given Number N ; Function Call
def minimumMoves ( n ) : NEW_LINE INDENT cnt2 = 0 NEW_LINE cnt5 = 0 NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT n //= 2 NEW_LINE cnt2 += 1 NEW_LINE DEDENT while ( n % 5 == 0 ) : NEW_LINE INDENT n //= 5 NEW_LINE cnt5 += 1 NEW_LINE DEDENT if ( n == 1 and cnt2 <= cnt5 ) : NEW_LINE INDENT return 2 * cnt5 - cnt2 NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 25 NEW_LINE print ( minimumMoves ( N ) ) NEW_LINE DEDENT