-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler_05.py
59 lines (47 loc) · 1.4 KB
/
euler_05.py
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
58
59
#################### 1 ####################
def prime_factors(num):
liste = []
while num != 1:
for i in range(2,num+1):
if num % i == 0:
liste.append(i)
num //= i
break
return liste
def smallest_multiple(number):
result = 1
for i in range(1,number+1):
factors = prime_factors(i)
last_number = result
for z in factors:
if last_number/z == int(last_number/z):
last_number /= z
else:
result *= z
print(f"Result:{result}")
smallest_multiple(20)
#################### 2 ####################
def prime_factors_dict(num):
prime_dict = {}
while num != 1:
for i in range(2,num+1):
if num % i == 0:
if i in prime_dict:
prime_dict[i] += 1
else:
prime_dict[i] = 1
num //= i
break
return prime_dict
def find_smallest_multiple(number):
result = 1
primes = dict()
for i in range(1,number+1):
prime = prime_factors_dict(i)
for q in prime:
if not q in primes or primes[q] < prime[q]:
primes[q] = prime[q]
for i in primes:
result *= i**(primes[i])
print(f"Result:{result}")
find_smallest_multiple(20)