I m trying to solver Problem 5 in projecteuler.The problem is as follows
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?
I have written a simple python program
primes = [2,3,5,7,11,13,17,19]
prod = 1
#function returns the list of prime factors of 'n'
def find_pf(n):
pf = []
for j in primes:
if i % j == 0:
pf.append(j)
return pf
#multiplies all the prime factors of all the numbers
#from 1[1..20]
for i in range(1,21):
lst = find_pf(i)
for i in lst:
prod *= i
#verifies that 'n' is diviible evenly by [1..20]
count = 0
def test_n(n):
global count
for i in range(1,21):
if n % i != 0:
count += 1
print ('smallest number divisible by [1..20] {}'.format(prod))
test_n(prod)
print('Total failures {}'.format(count))
The result obtained by the above program is
smallest number divisible by [1..20] 1055947052160000
Total failures 0
The answer 1055947052160000
is incorrect.? Can someone kindly point out what is wrong with the above program? Or suggest the correct method to solve this problem?