-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog.sf
67 lines (48 loc) · 1.17 KB
/
prog.sf
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
#!/usr/bin/ruby
# Prime(n) nested prime(n) times.
# https://oeis.org/A344946
# Known terms:
# 3, 11, 709, 167449, 88362852307, 156740126985437
# Bounds:
# 1168362263265154302969 < a(7) < 1176317776292085830502
# Better bounds:
# 1172447492997976103784 < a(7) < 1172447698513960075168
# a(7) = 1172447586903041169661 (found by Jinyuan Wang, Jul 12 2021)
func prime_count(n) is cached {
Num(`../../primecount #{n}`.strip)
}
func nth_prime_bsearch(n) is cached {
n == 0 && return 1 # not composite, but...
n <= 0 && return NaN
n == 1 && return 2
var min = n.prime_lower
var max = n.prime_upper
var k = bsearch_le(min, max, {|k|
prime_count(k) <=> n
})
while (!k.is_prime) {
--k
}
return k
}
func nth_prime(n) is cached {
#~ if (n <= 1e12) {
#~ return n.prime
#~ }
#~ return n.prime_lower
#~ return n.prime_upper
if (n <= 216289611853439384) {
return Num(`../../primecount -n #{n}`.strip)
}
nth_prime_bsearch(n)
}
func a(n) is cached {
var p = prime(n)
p.dec.times {
p = nth_prime(p)
}
return p
}
for n in (1..30) {
print(a(n), ", ")
}