Smallest number greater than or equal to N which is divisible by its non | Function to find the smallest number greater than or equal to N such that it is divisible by its non - zero digits ; Iterate in range [ N , N + 2520 ] ; To check if the current number satisfies the given condition ; Store the number in a temporary variable ; Loop until temp > 0 ; Check only for non zero digits ; Extract the current digit ; If number is divisible by current digit or not ; Otherwise , set possible to 0 ; Break out of the loop ; Divide by 10 ; Driver Code ; Function Call
def findSmallestNumber ( n ) : NEW_LINE INDENT for i in range ( n , n + 2521 ) : NEW_LINE INDENT possible = 1 NEW_LINE temp = i NEW_LINE while ( temp ) : NEW_LINE INDENT if ( temp % 10 != 0 ) : NEW_LINE INDENT digit = temp % 10 NEW_LINE if ( i % digit != 0 ) : NEW_LINE INDENT possible = 0 NEW_LINE break NEW_LINE DEDENT DEDENT temp //= 10 NEW_LINE DEDENT if ( possible == 1 ) : NEW_LINE INDENT print ( i , end = " " ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 31 NEW_LINE findSmallestNumber ( N ) NEW_LINE DEDENT