-
Notifications
You must be signed in to change notification settings - Fork 0
/
e095.py
60 lines (56 loc) · 1.66 KB
/
e095.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
60
from time import time
from script.maths import all_factors,primesd
t = time()
def e095(top=10**6):
div = [0 for i in range(top)]
for i in range(1,top):
for j in range(2*i, top, i):
div[j] += i
maxdict={}
testdict = {}
for i in range(len(div)):
tmp = div[i]
if testdict.get(i):continue
adict={div[i]:1}
testdict[i]=1
testdict[tmp]=1
while True:
try:tmp = div[tmp]
except:break
testdict[tmp]=1
if tmp>top:break
elif tmp==div[i]:
if len(adict)>len(maxdict):
maxdict = adict
print('i:',min(maxdict),' max:',len(maxdict),' time:',time()-t)
print(maxdict)
break
elif adict.get(tmp):break
else:adict[tmp]=1
if i ==12496:print(i)
return min(maxdict)
def e095_slow(top = 10**6):
p = primesd(top)
maxdict = {}
aset = set()
for i in range(2,top):
if i%10**3==0:print(i,time()-t)
if p.get(i):continue
adict = {}
tmp = i
while True:
tmp = sum(all_factors(tmp))-tmp
if p.get(tmp) or tmp>=top:break
elif adict.get(tmp):break
elif tmp==i:
adict[i] = 1
if len(adict)>len(maxdict):
maxdict = adict
print('i:',i,' max:',len(maxdict),' time:',time()-t)
print(maxdict)
break
else:adict[tmp]=1
if i ==14316:print(i)
return min(maxdict.keys())
if __name__=='__main__':
print(e095())