
EXAMPLE

Digits of 39741391:
in base 3 are 10, 100, 21, 11, 1, 10, 100, 1 and their concatenation is 1010021111101001 which is the prime 16090759 in base 10;
in base 4 are 3, 21, 13, 10, 1, 3, 21, 1 and their concatenation is 321131013211 which is the prime 15061477 in base 10;
in base 5 are 3, 14, 12, 4, 1, 3, 14, 1 and their concatenation is 31412413141 which is the prime 32935421 in base 10;
in base 6 are 3, 13, 11, 4, 1, 3, 13, 1 and their concatenation is 31311413131 which is the prime 196874767 in base 10;
in base 7 are 3, 12, 10, 4, 1, 3, 12, 1 and their concatenation is 31210413121 which is the prime 900203221 in base 10;
in base 8 are 3, 11, 7, 4, 1, 3, 11, 1 and their concatenation is 3117413111 which is the prime 423499337 in base 10;
in base 9 are 3, 10, 7, 4, 1, 3, 10, 1 and their concatenation is 3107413101 which is the prime 1209273301 in base 10.


MAPLE

P:= proc(q) local a, b, c, h, k, n, ok; for n from 1 by 2 to q do
if isprime(n) then ok:=1; for h from 3 to 9 do a:=[]; b:=n;
for k from 1 to ilog10(n)+1 do c:=convert(b mod 10, base, h);
if c=[] then c:=[0]; fi; b:=trunc(b/10);
a:=[op(a), op(c)]; od; a:=convert(a, base, h, 10); b:=0;
for k from nops(a) by 1 to 1 do b:=b*10+a[k]; od;
if not isprime(b) then ok:=0; break; fi; od;
if ok=1 then print(n); fi; fi; od; end: P(10^12);
