OFFSET
5,1
LINKS
Jean-Marc Rebert, Table of n, a(n) for n = 5..10000
EXAMPLE
prime(6) = 13 and the prime number 31 have the same set of digits {1,3}, and 31 is the smallest such number, hence a(6) = 31.
prime(13) = 41 and the prime number 4111 have the same set of digits {1,4}, and 4111 is the smallest such number, hence a(13) = 4111.
prime(20) = 71 and the prime number 1117 have the same set of digits {1,7}, and 1117 is the smallest such number, hence a(20) = 1117.
MAPLE
N:= 60: # for a(5)..a(N)
A:= Array(5..N):
R:= 1111111111111111111:
A[5]:= R: count:= 1:
for k from 6 while count < N-4 do
p:= ithprime(k);
S:= convert(convert(p, base, 10), set);
if assigned(V[S]) and V[S]<=N then A[V[S]]:= p; count:=count+1; fi;
V[S]:= k;
od:
convert(A, list); # Robert Israel, Oct 25 2022
PROG
(PARI) a(n)=my(m=Set(digits(prime(n)))); if(n<5, return()); if(n==5, return(1111111111111111111)); forprime(p=prime(n+1), , if(Set(digits(p))==m, return(p)))
(Python)
from sympy import isprime, prime
from itertools import count, product
def a(n):
pn = prime(n)
s = str(pn)
for d in count(len(s)):
for p in product(set(s), repeat=d):
if p[0] == "0": continue
t = int("".join(p))
if t > pn and isprime(t):
return t
print([a(n) for n in range(5, 56)]) # Michael S. Branicky, Oct 25 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Jean-Marc Rebert, Oct 24 2022
STATUS
approved