I have seen multiple questions on this problem but none seem to answer my specific question.
To start, the basic question is asking to find the smallest number that is divisible by numbers 1 to 20.
I have written some code that has solved the problem but the runtime is exceptionally too long for my liking. I guess I don't know enough about math the truly optimize my solution. I understand that iterating in increments of 1 is not the fastest, but I cant think of any other way.
def smallest_divisible(range_max): divisors = list(range(2,range_max+1,1)) #We ignore 1 because 1 is #divisible by everything x = 1 while True: x += 1 check = divisible(x, divisors) if check: return x def divisible(n, lst): #Pass a number to compare to a list to see if the number #is divisible by all elements in list return all(map(lambda y: n%y == 0, lst))