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 ; 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
function find_num ( n ) { var ans = 0 ; var sumOfDigitsN = 0 ; for ( var c = 0 ; c < n . length ; c ++ ) { sumOfDigitsN += n - ' ' ; } var x = 11 ; while ( true ) { var newNum = x * parseInt ( n ) ; var tempSumDigits = 0 ; var temp = ( newNum . toString ( ) ) ; for ( var c = 0 ; c < temp . length ; c ++ ) { tempSumDigits += temp - ' ' ; } if ( tempSumDigits == sumOfDigitsN ) { ans = x ; break ; } x ++ ; } document . write ( ans ) ; } var N = " " ; find_num ( N ) ;