Smallest multiple
Problem 5
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
python code :
import math
sqrt=math.sqrt
n=20
lst=[]
for i in range(2,n+1):
lst.append(i)
while 1:
k=1
for i in lst:
if n%i!=0:
k=0
break
if k==0:
n+=1
continue
else:
break
print(n)
运行结果: 232792560
运行时间:30s
效率不高,做了很多无用功,等待后续优化
时间: 2024-10-13 02:21:04