Smallest number not less than N which is divisible by all digits of N | Function to calculate the LCM ; Function to find the smallest number satisfying given constraints ; LCM value is 1 initially ; Finding the LCM of all non zero digits ; Update the value lcm ; Stores ceil value ; Print the answer ; Driver Code ; Function Call
function LCM ( A , B ) { return ( A * B / __gcd ( A , B ) ) ; } function findSmallestNumber ( X ) { let lcm = 1 ; let temp = X ; while ( temp > 0 ) { let last = temp % 10 ; temp = Math . floor ( temp / 10 ) ; if ( last == 0 ) continue ; lcm = LCM ( lcm , last ) ; } let answer = Math . floor ( ( X + lcm - 1 ) / lcm ) * lcm ; document . write ( answer ) ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let X = 280 ; findSmallestNumber ( X ) ;