Smallest number whose product with N has sum of digits equal to that of N | Function to find the minimum integer having sum of digits of a number multiplied by n equal to sum of digits of n ; Initialize answer ; Convert string to character array ; Find sum of digits of N ; Multiply N with x ; Sum of digits of the new number ; If condition satisfies ; Print answer ; Driver Code ; Function call
def find_num ( n ) : NEW_LINE INDENT ans = 0 NEW_LINE digitsOfN = str ( n ) NEW_LINE sumOfDigitsN = 0 NEW_LINE for c in digitsOfN : NEW_LINE INDENT sumOfDigitsN += int ( c ) NEW_LINE DEDENT for x in range ( 11 , 50 ) : NEW_LINE INDENT newNum = x * int ( n ) NEW_LINE tempSumDigits = 0 NEW_LINE temp = str ( newNum ) NEW_LINE for c in temp : NEW_LINE INDENT tempSumDigits += int ( c ) NEW_LINE DEDENT if ( tempSumDigits == sumOfDigitsN ) : NEW_LINE INDENT ans = x NEW_LINE break NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = "3029" NEW_LINE find_num ( N ) NEW_LINE DEDENT