The prime 1366733339 can be peeled down to a single digit by removing one digit at a time from either end to make a sequence of primes 136673333, 36673333, 3667333, 667333, 66733, 6673, 673, 67, 7.
Determine the largest integer for which this is possible.
I wrote a program to start with the list of 1-digit primes, and from that build a list of 2-digit peelable primes. Continuing this process and noting the number of primes in each list led to:
4, 16, 70, 243 which is oeis A298048
A298048: 4, 16, 70, 243, 638, 1450, 2819, 4951, 7629, 10677, 13267, 15182, 15923, 15796, 14369, 12547, 10291, 7939, 5703, 3911, 2559, 1595, 920, 561, 321, 167, 72, 37, 11, 6, 3
This suggests that there are 4 peelable primes that are each 31-digits long.
The largest I was able to get to was 11 digits: 99997925933
99997925933
9997925933
997925933
99792593
9792593
792593
92593
2593
593
59
5
==========
prefixes = '123456789'
postfixes = '13579'
big_list = [2,3,5,7]
loops = 11
listlist = [[2,3,5,7]]
for counter in range(loops):
small_list = big_list
big_list = []
for p in small_list:
for pre in prefixes:
larger = int(pre + str(p))
if isprime(larger):
big_list.append(larger)
for post in postfixes:
larger = int(str(p) + post)
if isprime(larger):
big_list.append(larger)
big_list = sorted(list(set(big_list)))
listlist.append(big_list)
print(counter+2, len(big_list))
if len(big_list) == 0:
print('none for', counter)
def peel(target):
s = str(target)
length = len(s)
peels = [[] for i in range(length-1)] + [[target]]
for k in range(length-1 , 0, -1):
for p in peels[k]:
a = int(str(p)[1:])
b = int(str(p)[:-1])
if isprime(a):
peels[k-1].append(a)
if isprime(b):
peels[k-1].append(b)
for k in range(length-1 , 0, -1):
print(peels[k])
return
|
Posted by Larry
on 2024-05-30 08:51:57 |