码迷,mamicode.com
首页 > 编程语言 > 详细

欧拉计划(python) problem 5

时间:2015-01-26 22:49:54      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:

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

效率不高,做了很多无用功,等待后续优化

欧拉计划(python) problem 5

标签:

原文地址:http://blog.csdn.net/zhangzhengyi03539/article/details/43162921

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!