Nth term of a sequence formed by sum of current term with product of its largest and smallest digit | Function to find integer ; Because 1 st integer is K itself ; Initialize min_d and max_d ; Updating min_d and max_d ; Break if min digit is 0 ; Driver code
def find ( K , N ) : NEW_LINE INDENT N = N - 1 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT curr_term = K NEW_LINE min_d = 9 NEW_LINE max_d = 0 NEW_LINE while curr_term > 0 : NEW_LINE INDENT r = int ( curr_term % 10 ) NEW_LINE min_d = min ( min_d , r ) NEW_LINE max_d = max ( max_d , r ) NEW_LINE curr_term = int ( curr_term / 10 ) NEW_LINE DEDENT if min_d == 0 : NEW_LINE break NEW_LINE K = K + min_d * max_d NEW_LINE return K NEW_LINE DEDENT DEDENT K = 487 NEW_LINE N = 2 NEW_LINE print ( find ( K , N ) ) NEW_LINE