-
Notifications
You must be signed in to change notification settings - Fork 1
/
095.boo
64 lines (51 loc) · 1.29 KB
/
095.boo
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
61
62
63
64
/*
Generate next numbers in amicable chain through a sieve-like algorithm.
That is, for each pair of divisors a and b, sum a+b to a*b. Be careful with
the squares.
Then, find all the strongly connected components through the classic algorithm
and get the greater of them and find the minimum value in it.
*/
import System
import System.Collections.Generic
import System.Linq.Enumerable
T = array(int, 1000001)
T2 = array(int, 1000001)
for i in range(T.Length):
T[i]+=1
for a in range(2, 1001):
T[a*a]+=a
b=a+1
while a*b < T.Length:
T[a*b]+=a+b
b+=1
for i in range(T.Length):
if T[i] < T.Length:
T2[T[i]]=i
V = array(int, T.Length)
O = array(int, T.Length)
C = array(int, T.Length)
maxv, maxx, count = 0,0,0
def dfs1(v as int) as void:
V[v] = 1
u = T[v]
if u<T.Length and not V[u]: dfs1(u)
O[count+=1]=v
def dfs2(v as int, c as int) as void:
V[v] = c
C[c] += 1
u = T[v]
if u<T.Length and not V[u]: dfs2(u, c)
for i in range(1, T.Length):
if not V[i]:
dfs1(i)
V = array(int, T.Length)
for i in range(1, T.Length):
if not V[O[i]]:
dfs2(O[i], O[i])
for i in range(T.Length):
if C[V[i]] > maxx:
maxx = C[V[i]]
maxv = i
answer = maxv
print answer
assert answer == 14316