-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.sf
111 lines (87 loc) · 5.45 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/ruby
# a(n) is the largest prime whose decimal expansion consists of the concatenation of a 1-digit prime, a 2-digit prime, a 3-digit prime, ..., and an n-digit prime.
# https://oeis.org/A338968
# Bernard Schott, Dec 21 2020:
# a(1) = 7 = A003618(1), and a(2) = 797 is the concatenation of A003618(1) and A003618(2); are there other similar terms a(n) with n > 30 that are the concatenation of A003618(1), A003618(2),..., A003618(n)?
# Daniel Suteu, Dec 26 2020:
# No other such prime exists for n <= 389. If another such prime exists, then it has more than 75855 digits.
# Let's define b(n) to be the concatenation of the first n terms of A003618.
# I will use the symbol "|" to mean concatenation.
# So, b(n) = A003618(1) | A003618(2) | ... | A003618(n)
# a(n) has the form b(n-1) concatenated with the largest prime p <= A003618(n) such that b(n-1)|p is prime.
# For example, in order for find a(3), we have b(2) = 7|97 and A003618(3) = 997:
# 7|97|997 is not prime (#1 fail)
# 7|97|991 is not prime (#2 fail)
# 7|97|983 is not prime (#3 fail)
# 7|97|977 is prime!
# Therefore, the largest prime p <= 997 such that b(2)|p is prime, is p = 977.
# We had to go back 3 primes from A003618(3) in order to find a(3).
# How many primes we have to go back to find a(n):
# 0, 0, 3, 3, 16, 40, 8, 44, 112, 85, 48, 24, 168, 15, 182, 18, 13, 151, 348, 204, 437, 612, 771, 75, 51, 310, 796, 111, 811, 350, 644, 350, 469, 159, 571, 544, 2239, 4, 1474, 97, 2177, 175, 1400, 1791, 75, 1983, 337, 2503, 854, 2397, 830, 246, 5350, 1682, 153, 1581, 622, 1996, 658, 2644, ...
# Number of divisors of b(n):
# 2, 2, 8, 16, 8, 4, 64, 4, 32, 8, 128, 64, 16, 64, ...
# Prime factorization of b(n):
# 7 = 7
# 797 = 797
# 797997 = 3 * 17 * 15647
# 7979979973 = 7 * 23 * 137 * 361789
# 797997997399991 = 37 * 951649 * 22663307
# 797997997399991999983 = 3023681 * 263916067005743
# 7979979973999919999839999991 = 43 * 53 * 373 * 13187 * 1821923 * 390726277573
# 797997997399991999983999999199999989 = 1249 * 638909525540425940739791832826261
# 797997997399991999983999999199999989999999937 = 7 * 37 * 8423 * 2999071 * 121968726514493097477773636282371
# 7979979973999919999839999991999999899999999379999999967 = 3 * 195822397 * 13583703219947001261284053549809218026611462937
# 797997997399991999983999999199999989999999937999999996799999999977 = 23 * 97 * 431567 * 471137 * 10591411 * 55410546381777178673 * 2997509281326668130078491
# 797997997399991999983999999199999989999999937999999996799999999977999999999989 = 11 * 17 * 14947 * 244333 * 3901049532954226673883119 * 299531546129341367046122774317187785383863
# 7979979973999919999839999991999999899999999379999999967999999999779999999999899999999999971 = 3 * 10889117 * 45838430515264298044087 * 5329152440050359524991399301341957112695039971439457149027283
# 797997997399991999983999999199999989999999937999999996799999999977999999999989999999999997199999999999973 = 19 * 59 * 145487 * 306853 * 14087630993 * 1131888530760989527650727686899841153211611294760163296614906730111795795956155231
# From the factorization data, it may seem plausible to conjecture that b(n) is always squarefree, but it's actually not true!
# For each n in {21, 31, 32, 39, 42, 62, 67, 75, 82, 91, 93, 97, 104, 109, 121, 127, 135, 137, 139, 140, 145, 146, ...}, b(n) is not squarefree.
func f(n) is cached {
prev_prime(10**n)
}
func a(n) {
var prefix = (n-1).of { f(_+1) }.join
var suffix = f(n)
loop {
var t = join('', prefix, suffix).to_i
if (t.is_prime) {
return t
}
suffix.prev_prime!
}
}
#~ for n in (1..20) {
#~ say "#{n} #{a(n)}"
#~ }
for n in (390..1000) {
var p = n.of { f(_+1) }.join.to_i
say "Testing: n = #{n} with #{p.len} digits..."
if (p.is_prob_prime) {
say "Found prime for n = #{n}"
if (n > 3) {
die "Found prime for n = #{n}"
}
}
}
__END__
1 7
2 797
3 797977
4 7979979941
5 797997997399817
6 797997997399991999371
7 7979979973999919999839999901
8 797997997399991999983999999199999131
9 797997997399991999983999999199999989999997639
10 7979979973999919999839999991999999899999999379999997871
11 797997997399991999983999999199999989999999937999999996799999998951
12 797997997399991999983999999199999989999999937999999996799999999977999999999359
13 7979979973999919999839999991999999899999999379999999967999999999779999999999899999999994939
14 797997997399991999983999999199999989999999937999999996799999999977999999999989999999999997199999999999469
15 797997997399991999983999999199999989999999937999999996799999999977999999999989999999999997199999999999973999999999993157
16 7979979973999919999839999991999999899999999379999999967999999999779999999999899999999999971999999999999739999999999999899999999999999389
17 797997997399991999983999999199999989999999937999999996799999999977999999999989999999999997199999999999973999999999999989999999999999993799999999999999457
18 797997997399991999983999999199999989999999937999999996799999999977999999999989999999999997199999999999973999999999999989999999999999993799999999999999997999999999999994481
19 7979979973999919999839999991999999899999999379999999967999999999779999999999899999999999971999999999999739999999999999899999999999999937999999999999999979999999999999999899999999999999985471
20 797997997399991999983999999199999989999999937999999996799999999977999999999989999999999997199999999999973999999999999989999999999999993799999999999999997999999999999999989999999999999999996199999999999999990503