-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactors.py
47 lines (45 loc) · 1000 Bytes
/
Factors.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
import time
start = time.time()
def factors(num):
L = list()
factors = list()
i = 2
while i < num:
if num%i == 0:
L.append(i)
num = int(num/i)
i = 2
continue
if i == num-1:
L.append(num)
i += 1
print(L)
print(len(L), sum(L))
i = 0
_len = len(L)
while i < _len-1:
j = i+1
p = L[i]
while j < _len and _len > 2:
y = L[i]*L[j]
if y not in L:
L.append(y)
if not (i == 0 and j==_len-1):
p*=L[j]
if p not in L:
L.append(p)
j+=1
i+=1
for x in L:
if x not in factors:
factors.append(x)
return [1]+factors
print(factors(33550336))
# bad algorithm
# L = list([1])
# for i in range(2,int(33550336/2+1)):
# if 33550336 % i == 0:
# L.append(i)
# print(len(L), sum(L))
# print(L)
print(time.time()-start)