OFFSET
1,1
COMMENTS
A Xmas tree prime is a prime which is a concatenation of a prime with a single digit, a prime with two digits, a prime with three digits, a prime with four digits etc. By definition, the number of digits is a triangular number (A000217). Leading zeros are not allowed for any of the primes.
LINKS
Harvey P. Dale, Table of n, a(n) for n = 1..2237 (* All terms through concatenation of one-, two-, and three-digit primes. *)
Terry Trotter, POTPOURRI
EXAMPLE
359 is a Xmas tree prime because it is prime and 3 and 59 are prime.
503 is not a Xmas tree prime although 5 and 3 are prime, because the leading 0 in front of the 3 is not allowed by definition.
MAPLE
isA000217 := proc(n)
for k from 0 do
if n = k*(k+1)/2 then
return k;
elif n < k*(k+1)/2 then
return -1 ;
end if;
end do;
end proc:
isA195302 := proc(n)
local dgs, T, d, std, kList, k ;
if isprime(n) then
dgs := convert(n, base, 10) ;
T := isA000217(nops(dgs)) ;
if T > 0 then
std := 1 ;
for d from T to 1 by -1 do
kList := [op(std..std+d-1, dgs)] ;
if op(-1, kList) = 0 then
return false;
end if;
k := add(op(i, kList)*10^(i-1), i=1..nops(kList)) ;
if not isprime(k) then
return false;
end if;
std := std+d ;
end do:
return true;
else
false;
end if;
else
false;
end if;
end proc:
for i from 2 to 300000 do
if isA195302(i) then
printf("%d, ", i) ;
end if;
end do: # R. J. Mathar, Sep 20 2011
MATHEMATICA
With[{p1=Prime[Range[4]]}, {p2=Prime[Range[5, 25]]}, {p3=Prime[Range[26, 168]]}, xmas2=Select[Flatten[Table[100p1[[m]]+p2[[n]], {m, 4}, {n, 21}]], PrimeQ]; xmas3=Select[Flatten[Table[100000p1[[a]]+1000p2[[b]]+p3[[c]], {a, 4}, {b, 20}, {c, 143}]], PrimeQ]; Join[p1, xmas2, xmas3]] (* Harvey P. Dale, Apr 04 2026 *)
PROG
(Python)
from sympy import isprime, sieve
from itertools import product
def alst(n):
alst, plen = [], 1
while True:
sieve.extend(10**plen-1)
primes = list(str(p) for p in sieve._list)
primesbylen = [[p for p in primes if len(p)==i+1] for i in range(plen)]
for t in product(*primesbylen):
intt = int("".join(t))
if isprime(intt): alst.append(intt)
if len(alst) == n: return alst
plen += 1
print(alst(57)) # Michael S. Branicky, Dec 26 2020
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Kausthub Gudipati, Sep 16 2011
STATUS
approved
