欧拉问题集,第五题,最小公倍数
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))