-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler_problem005.py
More file actions
57 lines (42 loc) · 1.02 KB
/
euler_problem005.py
File metadata and controls
57 lines (42 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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?
# alternative implementation making use of prime factors
def isPrime(number):
for i in range(2, number):
if number % i == 0:
return False
return True
primes = []
for i in range(2,21):
if isPrime(i):
primes.append(i)
factors = []
count = 1
for i in primes:
while i ** count < 20:
factors.append(i)
count += 1
if i ** count > 20:
count = 1
print(factors)
smallest_multiple = 1
for j in factors:
smallest_multiple *= j
print(smallest_multiple)
# original implementation
# num = 1
# multiples_list = []
# for divisor in range(1,21):
# multiples_list.append(divisor)
# index = len(multiples_list) - 2
# while index > 0:
# multiple = 20 * num
# if multiple % multiples_list[index] == 0:
# index -= 1
# else:
# num += 1
# index = len(multiples_list) - 2
# if index == 0:
# print(multiple)