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?
The answer to this problem is to find the l.c.m of the numbers 1,2,3,.......,18,19,20
Python Code
def smallestMultiple():
lcm = 2
tup = [0 for i in range(20)]
for i in range(20):
tup[i] = i+1
while lcm > 1:
count = 0
for i in range(20):
if lcm%tup[i] == 0:
count = count+1
else:
break
if count != 20:
lcm = lcm+1
else:
break
print lcm
smallestMultiple()
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
The answer to this problem is to find the l.c.m of the numbers 1,2,3,.......,18,19,20
Python Code
def smallestMultiple():
lcm = 2
tup = [0 for i in range(20)]
for i in range(20):
tup[i] = i+1
while lcm > 1:
count = 0
for i in range(20):
if lcm%tup[i] == 0:
count = count+1
else:
break
if count != 20:
lcm = lcm+1
else:
break
print lcm
smallestMultiple()
No comments:
Post a Comment