Smallest number not less than N which is divisible by all digits of N | C ++ 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
#include " bits / stdc + + . h " NEW_LINE using namespace std ; int LCM ( int A , int B ) { return ( A * B / __gcd ( A , B ) ) ; } int findSmallestNumber ( int X ) { int lcm = 1 ; int temp = X ; while ( temp ) { int last = temp % 10 ; temp /= 10 ; if ( ! last ) continue ; lcm = LCM ( lcm , last ) ; } int answer = ( ( X + lcm - 1 ) / lcm ) * lcm ; cout << answer ; } int main ( ) { int X = 280 ; findSmallestNumber ( X ) ; return 0 ; }