-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem95.pir
84 lines (68 loc) · 1.38 KB
/
problem95.pir
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
.sub foo
.local pmc all_sums
.local pmc all_lengths
.local pmc visited
new all_sums, "Hash"
new all_lengths, "Hash"
$I0 = 0
INIT_LOOP:
if $I0 > 1000000 goto INIT_DONE
all_sums[$I0] = 0
all_lengths[$I0] = 0
$I0 += 1
goto INIT_LOOP
INIT_DONE:
$I1 = 1
SUM_LOOP:
if $I1 > 1000000 goto SUM_DONE
$I2 = 2 * $I1
SUM_INNER_LOOP:
if $I2 > 1000000 goto SUM_INNER_DONE
$I3 = all_sums[$I2]
$I4 = $I3 + $I1
all_sums[$I2] = $I4
$I2 += $I1
goto SUM_INNER_LOOP
SUM_INNER_DONE:
$I1 += 1
goto SUM_LOOP
SUM_DONE:
$I5 = 1
LENGTH_LOOP:
if $I5 > 1000000 goto LENGTH_DONE
$I6 = $I5
new visited, "Hash"
$I8 = 0
LENGTH_INNER_LOOP:
$I7 = visited[$I6]
if $I7 > 0 goto LENGTH_INNER_DONE
visited[$I6] = 1
$I6 = all_sums[$I6]
$I8 += 1
if $I6 <= 0 goto LENGTH_INNER_DONE
if $I6 > 999999 goto LENGTH_INNER_DONE
if $I6 < $I5 goto LENGTH_INNER_DONE
goto LENGTH_INNER_LOOP
LENGTH_INNER_DONE:
if $I6 != $I5 goto DONT_WRITE
all_lengths[$I5] = $I8
DONT_WRITE:
$I5 += 1
goto LENGTH_LOOP
LENGTH_DONE:
$I9 = 0
$I10 = 0
$I11 = 1
BEST_LOOP:
if $I11 > 1000000 goto BEST_END
$I12 = all_lengths[$I11]
if $I12 <= $I9 goto BEST_CONTINUE
$I9 = $I12
$I10 = $I11
BEST_CONTINUE:
$I11 += 1
goto BEST_LOOP
BEST_END:
print $I10
print "\n"
.end