[go: up one dir, main page]

login
A359115
a(n) is the smallest odd prime not already in the sequence such that when the terms a(1)..a(n) are concatenated, the result is the reverse of a prime.
0
3, 5, 11, 7, 29, 37, 89, 211, 71, 241, 347, 331, 23, 457, 233, 31, 53, 67, 17, 181, 107, 1051, 173, 421, 113, 103, 491, 601, 1607, 223, 1187, 1093, 257, 643, 839, 1021, 557, 2731, 1301, 1213, 761, 1861, 239, 673, 2069, 2083, 317, 73, 599, 571, 191, 631, 1451
OFFSET
1,1
COMMENTS
From any term back to and including the first, digit by digit, right to left, we can read the resulting primes backwards.
EXAMPLE
a(3) = 11 because 11 is the smallest unused odd prime such that the concatenated reverse terms R(a(3))||R(a(2))||R(a(1)) = 1153 is prime. Trying the smallest unused odd prime 7 fails because 753 = 3*251, a composite number.
a(5) = 29 as its reverse 92 concatenated with the reversed chain of the previous reversed terms 7, 11, 5, 3, gives 9271153, a prime, and no smaller unused odd prime satisfies that condition.
MAPLE
rev:= proc(n) local L, i; L:= convert(n, base, 10); add(L[-i]*10^(i-1), i=1..nops(L)) end proc:
tcat:= proc(a, b) 10^(1+ilog10(b))*a+b end proc:
Q:= 3: S:= {3}: p:= 3: count:= 1: R:= 3:
while count < 100 do
q:= p;
do
if not member(q, S) then
rq:= rev(q);
if isprime(tcat(rq, Q)) then
count:= count+1;
R:= R, q;
Q:= tcat(rq, Q);
S:= S union {q};
if q = p then p:= nextprime(p) fi;
break
fi;
fi;
q:= nextprime(q);
od;
od:
R; # Robert Israel, Dec 21 2022
MATHEMATICA
a[1] = 3; a[n_] := a[n] = Module[{s = Array[a, n - 1], p = 5}, While[MemberQ[s, p] || ! PrimeQ[FromDigits @ Reverse @ Flatten @ IntegerDigits[Join[s, {p}]]], p = NextPrime[p]]; p]; Array[a, 50] (* Amiram Eldar, Dec 17 2022 *)
PROG
(Python)
from itertools import islice
from sympy import isprime, nextprime
def agen(): # generator of terms
alst, aset, arev, minp = [], set(), "", 3
while True:
p = minp
while p in aset or not isprime(int(str(p)[::-1] + arev)):
p = nextprime(p)
yield p; alst.append(p); aset.add(p); arev = str(p)[::-1] + arev
while minp in aset: minp = nextprime(minp)
print(list(islice(agen(), 53))) # Michael S. Branicky, Dec 16 2022
CROSSREFS
Sequence in context: A087322 A094747 A300783 * A287939 A129738 A271314
KEYWORD
nonn,base
AUTHOR
Tamas Sandor Nagy, Dec 16 2022
STATUS
approved