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
< ? php function gcd ( $ a , $ b ) { return ( $ a % $ b ) ? gcd ( $ b , $ a % $ b ) : $ b ; } function LCM ( $ x , $ y , $ z ) { $ ans = floor ( ( $ x * $ y ) / ( gcd ( $ x , $ y ) ) ) ; return floor ( ( $ z * $ ans ) / ( gcd ( $ ans , $ z ) ) ) ; } function findDivisible ( $ n , $ x , $ y , $ z ) { $ lcm = LCM ( $ x , $ y , $ z ) ; $ ndigitnumber = pow ( 10 , $ n - 1 ) ; $ reminder = $ ndigitnumber % $ lcm ; if ( $ reminder == 0 ) return $ ndigitnumber ; $ ndigitnumber += $ lcm - $ reminder ; if ( $ ndigitnumber < pow ( 10 , $ n ) ) return $ ndigitnumber ; else return 0 ; } $ n = 4 ; $ x = 2 ; $ y = 3 ; $ z = 5 ; $ res = findDivisible ( $ n , $ x , $ y , $ z ) ; if ( $ res != 0 ) echo $ res ; else echo " Not ▁ possible " ; ? >