login
A392504
Smallest prime p, distinct from prime(n), that uses exactly the same set of digits as prime(n), and -1 if no such prime exists.
0
-1, -1, -1, -1, 1111111111111111111, 31, 71, 191, 223, 229, 13, 73, 4111, 433, 4447, 353, 599, 661, 677, 17, 37, 97, 383, 8999, 79, 10111, 1013, 701, 1009, 13, 271, 13, 173, 193, 419, 1151, 571, 613, 617, 137, 197, 811, 19, 139, 179, 19, 2111, 23, 277, 29, 23, 293, 421, 521, 2557
OFFSET
1,5
COMMENTS
First differs from A358020 at a(11) = 13 != 113 = A358020(11). - Michael S. Branicky, Feb 20 2026
EXAMPLE
a(6) = 31, because 13 and 31 use the same set of digits, and no smaller prime distinct from 13 has this property.
PROG
(PARI) a(n) = if (n<=4, return(-1)); if (n==5, my(p=prime(n), s=Set(digits(p)), q=1); while (!((q!=p) && isprime(q)), q = eval(concat(q, "1"))); return(q)); my(p=prime(n), s=Set(digits(p)), q=2); while(!((Set(digits(q)) == s) && (p!=q)), q=nextprime(q+1)); q; \\ Michel Marcus, Feb 19 2026
(Python)
from sympy import isprime, prime
from itertools import count, product
def a(n):
if n < 5: return -1
pn = prime(n)
S = sorted(set(str(pn)))
for d in count(len(S)):
for p in product(S, repeat=d):
if p[0] == "0" or len(set(p)) != len(S): continue
t = int("".join(p))
if t != pn and isprime(t):
return t
print([a(n) for n in range(1, 56)]) # Michael S. Branicky, Feb 20 2026
CROSSREFS
KEYWORD
sign,base
AUTHOR
Jean-Marc Rebert, Feb 19 2026
STATUS
approved