login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A039999
Number of permutations of digits of n which yield distinct primes.
17
0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 2, 1, 0, 1, 1, 0, 2, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 2, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 2, 1, 0, 0, 2, 0, 3, 2, 0
OFFSET
1,13
COMMENTS
Consider all k! permutations of digits of a k-digit number n, discard initial zeros, count distinct primes.
LINKS
EXAMPLE
a(20) = 1, since from {02, 20} we get {2,20} and only 2 is prime.
From 107 we get 4 primes: (0)17, (0)71, 107 and 701; so a(107) = 4.
MATHEMATICA
Table[Count[FromDigits/@Permutations[IntegerDigits[n]], _?PrimeQ], {n, 110}] (* Harvey P. Dale, Jun 26 2011 *)
PROG
(PARI) for(x=1, 400, print1(permprime(x), ", ")) /* for definition of function permprime cf. link */ \\ Cino Hilliard, Jun 07 2009
(PARI) A039999(n, D=vecsort(digits(n)), S)={forperm(D, p, isprime(fromdigits(Vec(p))) && S++); S} \\ Giving the 2nd arg avoids computing it and increases efficiency when the digits are already known. Must be sorted because forperm() only considers "larger" permutations. - M. F. Hasler, Oct 14 2019
(Magma) [ #[ s: s in Seqset([ Seqint([m(p[i]):i in [1..#x] ], 10): p in Permutations(Seqset(x)) ]) | IsPrime(s) ] where m is map< x->y | [<x[i], y[i]>:i in [1..#x] ] > where x is [1..#y] where y is Intseq(n, 10): n in [1..120] ]; // Klaus Brockhaus, Jun 15 2009
(Haskell)
import Data.List (permutations, nub)
a039999 n = length $ filter ((== 1) . a010051)
(map read (nub $ permutations $ show n) :: [Integer])
-- Reinhard Zumkeller, Feb 07 2011
(Python)
from sympy import isprime
from itertools import permutations
def a(n): return len(set(t for p in permutations(str(n)) if isprime(t:=int("".join(p)))))
print([a(n) for n in range(1, 106)]) # Michael S. Branicky, Feb 17 2024
CROSSREFS
Cf. A046810.
Cf. A039993 (number of primes embedded in n), A076730 (maximum for n digits), A072857 (record indices: primeval numbers), A134596 (largest with n digits).
Cf. A075053 (as A039993 but counted with multiplicity), A134597 (maximum for n digits).
Sequence in context: A356682 A323989 A262988 * A069842 A083056 A356733
KEYWORD
nonn,base,nice
EXTENSIONS
Contribution of Cino Hilliard edited by Klaus Brockhaus, Jun 15 2009
Edited by M. F. Hasler, Oct 14 2019
STATUS
approved