您的位置:首页 > 理论基础 > 计算机网络

https://projecteuler.net/problem=5

2016-02-23 21:11 567 查看
欧拉问题集,第五题,最小公倍数


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?

#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?

#最大公约数
def gcd(a,b):
if a < b:
return gcd(b,a)
if b == 0:
return a
else:
return gcd(b,a%b)
#最大公倍数
def hcf(a,b):
return a * b / gcd(a,b)
#区间最小公倍数
def rangeHcf(start,end):
result = start
for i in range(start,end+1):
result = hcf(result,i)
return result

print(rangeHcf(1,20))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: