Append X digits to the end of N to make it divisible by M | Base case ; If N is divisible by M ; global variable to store result ; Iterate over the range [ 0 , 9 ] ; if N is Divisible by M upon appending X digits ; Driver Code ; Stores the number by appending X digits on the right side of N
if ( X == 0 ) : NEW_LINE INDENT if ( N % M == 0 ) : NEW_LINE INDENT global res NEW_LINE res = N NEW_LINE return True NEW_LINE DEDENT return False NEW_LINE DEDENT res = - 1 NEW_LINE def isDiv ( N , X , M ) : NEW_LINE INDENT for i in range ( 10 ) : NEW_LINE INDENT if ( isDiv ( N * 10 + i , X - 1 , M ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N , M , X = 4 , 50 , 2 NEW_LINE if ( isDiv ( N , X , M ) ) : NEW_LINE INDENT print ( res ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT DEDENT