Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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?
- #Algorithm from http://en.wikipedia.org/wiki/Least_common_multiple
- #A simple algorithm section
- primes=[2,3,5,7,11,13,17,19]
- myRange = range(1,21)
- def checkOnes(l):
- for i in range(len(l)):
- if l[i] != 1:
- return False
- return True
- def checkDev(l,p):
- for i in range(len(l)):
- if l[i]%p == 0:
- return True
- return False
- x = []
- i = 0
- while not checkOnes(myRange):
- while checkDev(myRange,primes[i]):
- x.append(primes[i])
- for j in range(len(myRange)):
- if myRange[j] % primes[i] == 0:
- myRange[j] = myRange[j] / primes[i]
- i += 1
- ans = 1
- for k in x:
- ans *= k
- print ans
Advertisement
Add Comment
Please, Sign In to add comment