Number formed by adding product of its max and min digit K times | Function to find the formed number ; K -= 1 M ( 1 ) = N ; Check if minimum digit is 0 ; Function that returns the product of maximum and minimum digit of N number . ; Find the last digit . ; Moves to next digit ; Driver Code
def formed_no ( N , K ) : NEW_LINE INDENT if ( K == 1 ) : NEW_LINE INDENT return N NEW_LINE DEDENT answer = N NEW_LINE while ( K != 0 ) : NEW_LINE INDENT a_current = prod_of_max_min ( answer ) NEW_LINE if ( a_current == 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT answer += a_current NEW_LINE K -= 1 NEW_LINE DEDENT return answer NEW_LINE DEDENT def prod_of_max_min ( n ) : NEW_LINE INDENT largest = 0 NEW_LINE smallest = 10 NEW_LINE while ( n != 0 ) : NEW_LINE INDENT r = n % 10 NEW_LINE largest = max ( r , largest ) NEW_LINE smallest = min ( r , smallest ) NEW_LINE n = n // 10 NEW_LINE DEDENT return largest * smallest NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 487 NEW_LINE K = 100000000 NEW_LINE print ( formed_no ( N , K ) ) NEW_LINE DEDENT