Smallest number not less than N which is divisible by all digits of N | Python3 program for the above approach ; 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
import math NEW_LINE def LCM ( A , B ) : NEW_LINE INDENT return ( A * B // math . gcd ( A , B ) ) NEW_LINE DEDENT def findSmallestNumber ( X ) : NEW_LINE INDENT lcm = 1 NEW_LINE temp = X NEW_LINE while ( temp ) : NEW_LINE INDENT last = temp % 10 NEW_LINE temp //= 10 NEW_LINE if ( not last ) : NEW_LINE INDENT continue NEW_LINE DEDENT lcm = LCM ( lcm , last ) NEW_LINE DEDENT answer = ( ( X + lcm - 1 ) // lcm ) * lcm NEW_LINE print ( answer ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = 280 NEW_LINE findSmallestNumber ( X ) NEW_LINE DEDENT