Smallest n digit number divisible by given three numbers |  ; LCM for x , y , z ; returns smallest n digit number divisible by x , y and z ; find the LCM ; find power of 10 for least number ; reminder after ; If smallest number itself divides lcm . ; add lcm - reminder number for next n digit number ; this condition check the n digit number is possible or not if it is possible it return the number else return 0 ; Driver Code ; if number is possible then it print the number
function __gcd ( a , b ) { if ( b == 0 ) { return a ; } else { return __gcd ( b , a % b ) ; } } function LCM ( x , y , z ) { let ans = ( ( x * y ) / ( __gcd ( x , y ) ) ) ; return ( ( z * ans ) / ( __gcd ( ans , z ) ) ) ; } function findDivisible ( n , x , y , z ) { let lcm = LCM ( x , y , z ) ; let ndigitnumber = Math . pow ( 10 , n - 1 ) ; let reminder = ndigitnumber % lcm ; if ( reminder == 0 ) return ndigitnumber ; ndigitnumber += lcm - reminder ; if ( ndigitnumber < Math . pow ( 10 , n ) ) return ndigitnumber ; else return 0 ; } let n = 4 , x = 2 , y = 3 , z = 5 ; let res = findDivisible ( n , x , y , z ) ; if ( res != 0 ) document . write ( res ) ; else document . write ( " " ) ;