OFFSET
1,1
COMMENTS
Sequence consists of the primes in which, for each j in 1..N (where N is the number of digits), j is the j-th digit, or is the k-th digit where k is the j-th digit, or is 0.
Equivalently, terms are primes that can be obtained from the number 1234..N (where N is the number of digits) by swapping the positions of zero or more pairs of digits and replacing zero or more unswapped digits with 0's. (Leading zeros are not allowed, so the '1' cannot be replaced with a 0.)
The maximum number of digits N is 9.
The last term is 987400321.
Some terms were found by Claudio Meller.
This sequence has 1404 terms. - David A. Corneth, Sep 26 2021
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..1404
Michael S. Branicky, Python program for complete sequence
EXAMPLE
103 is a term because it is a prime number, 1 is the 1st digit, 3 is the 3rd digit, and there is no digit 2, so the 2nd digit is 0.
1 2 3
| . |
| . |
1 0 3
2143 is a term because it is a prime number, 1 and 2 are the 2nd and 1st digits, respectively, and 3 and 4 are the 4th and 3rd digits, respectively.
1 2 3 4
\ / \ /
X X
/ \ / \
2 1 4 3
146203 is a term because it is a prime number, 1 is the 1st digit, 2 and 4 are the 4th and 2nd digits, respectively, 3 and 6 are the 6th and 3rd digits, respectively, and there is no digit 5, so the 5th digit is a 0:
1 2 3 4 5 6
| \ \ / . /
| \ X__ __/
| \ / \ /.
| X X .
| / \ __/ \__
| / X . \
| / / \ . \
1 4 6 2 0 3
.
1 2 3 4 5 6 digit positions
digit = 1 4 6 2 0 3
^-------^ 2,4 swapped
^-----------^ 3,6 swapped
.
1 2 3 4 5 6 digit positions
digit = 1 4 6 2 0 3
^-----^ 2,4 swapped
^--------^ 3,6 swapped
MATHEMATICA
q[n_] := Module[{d = IntegerDigits[n], nd}, nd = Length[d]; AllTrue[Range[nd], d[[#]] == 0 || (d[[#]] <= nd && d[[d[[#]]]] == # ) &]]; Select[Range[1070063], PrimeQ[#] && q[#] &] (* Amiram Eldar, Sep 26 2021 *)
PROG
(PARI) is(n) = { if(!isprime(n), return(0)); my(d = digits(n), f = vector(10), s); for(i = 1, #d, f[d[i]+1]++; if(f[d[i]+1] > 1 && d[i]!=0, return(0))); for(i = 1, #d, if(d[i] == 0 && f[i+1]>0, return(0) ); if(f[d[i]+1] > 0 && #d < d[i], return(0)); if(d[i] > 0 && d[d[i]] != i, return(0)); ); 1 } \\ David A. Corneth, Sep 26 2021
(Python) # see link for faster version for generating entire sequence
from sympy import isprime
def ok(n):
if n%10 not in {1, 3, 7, 9}: return False
digs = str(n)
if int(max(digs)) != len(digs): return False
for j, dj in enumerate(digs, start=1):
if dj != '0' and digs[int(dj)-1] != str(j): return False
return isprime(n)
print(list(filter(ok, range(1070064)))) # Michael S. Branicky, Sep 26 2021
CROSSREFS
KEYWORD
nonn,base,fini
AUTHOR
Rodolfo Kurchan, Sep 25 2021
EXTENSIONS
More terms from and new name from David A. Corneth, Sep 26 2021
STATUS
approved