I am trying to make a script that figures out the least number divisible by numbers from 1 to 20 without any remainder. Apparently it works well with finding the least number that can be divided from 1 to 10 which is 2520, but for the former problem it takes a lot of time to actually find it because the number is much bigger than 2520 (232792560). So is there anyway to make that process faster, I am totally new to Python by the way. Here is the code I used:
num = 1
oper = 1
while oper <= 20:
y = num % oper
if y == 0:
oper += 1
else:
num += 1
oper = 1
print(num)
oper = 1is a waste of time: all numbers are divisible by 1. Similarly, there's no point checking the odd numbers: none of them will be divisible by 2, let alone the larger even divisors. Start withnum = 2, resetoper = 2for each number, and incrementnum += 2.