login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

A379761
Beginning with 7, least prime such that concatenation of first n terms and its digit reversal both are primes.
1
7, 3, 3, 31, 389, 1021, 2243, 1831, 5849, 15361, 9887, 3877, 4157, 919, 22637, 14449, 27617, 80221, 5039, 51043, 14009, 126079, 24443, 68311, 49193, 47059, 13049, 253681, 271409, 221227, 138869, 116953, 146297, 21841, 1211549, 322501, 212633, 281791, 216071, 1901749, 38747, 116437
OFFSET
1,1
LINKS
J.W.L. (Jan) Eerland, Table of n, a(n) for n = 1..100
EXAMPLE
31 is a term because the concatenation of {7,3,3,31} and {13,3,3,7} are respectively 73331 and 13337 which are both prime.
2243 is a term because the concatenation of {7,3,3,31,389,1021,2243} and {3422,1201,983,13,3,3,7} are respectively 7333138910212243 and 3422120198313337 which are both prime.
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)
a*10^(1+ilog10(b))+b
end proc:
A:= 7: x:= 7:
for i from 1 to 50 do
p:= 2:
do
p:= nextprime(p);
y:= tcat(x, p);
if isprime(y) and isprime(rev(y)) then
A:= A, p;
x:= y;
break
fi;
od
od:
A; # after Robert Israel in A113584
MATHEMATICA
w={7}; Do[k=1; q=Monitor[Parallelize[While[True, If[PrimeQ[FromDigits[Join@@IntegerDigits/@Reverse[IntegerDigits[FromDigits[Join@@IntegerDigits/@Append[w, Prime[k]]]]]]]&&PrimeQ[FromDigits[Join@@IntegerDigits/@Append[w, Prime[k]]]], Break[]]; k++]; Prime[k]], {i, k}]; w=Append[w, q], {i, 2, 50}]; w
PROG
(Python)
from itertools import count, islice
from gmpy2 import digits, is_prime, mpz, next_prime
def agen(): # generator of terms
s, r, an = "", "", 7
while True:
yield int(an)
d = digits(an)
s, r, p, sp = s+d, d[::-1]+r, 3, "3"
while not is_prime(mpz(s+sp)) or not is_prime(mpz(sp[::-1]+r)):
p = next_prime(p)
sp = digits(p)
an = p
print(list(islice(agen(), 40))) # Michael S. Branicky, Jan 02 2025
CROSSREFS
KEYWORD
base,nonn,changed
AUTHOR
STATUS
approved