-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem005.py
49 lines (39 loc) · 1.14 KB
/
problem005.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
#!/bin/python3
#fractional decomposition function
def factorization(n):
i = 2
factors = {}
while i <= n ** 0.5:
if n % i == 0:
fact1 = factorization(i)
fact2 = factorization(n / i)
for j in fact2:
if j in fact1:
fact1[j] += fact2[j]
else:
fact1[j] = fact2[j]
factors = fact1
break
i += 1
if len(factors) == 0:
factors = {int(n):1}
return factors
def find_smallest_multiple(n):
factor_dict = {}
for i in range(1, n + 1):
fact1 = factorization(i)
for j in fact1:
if j in factor_dict:
factor_dict[j] = max(factor_dict[j], fact1[j])
else:
factor_dict[j] = fact1[j]
smallest_multiple = 1
for i in factor_dict:
smallest_multiple = smallest_multiple * pow(i, factor_dict[i])
return smallest_multiple
result = []
t = int(input().strip())
for a0 in range(t):
n = int(input().strip())
result.append(str(find_smallest_multiple(n)))
print('\n'.join(result))