How many 3-digit primes with 3 distinct digits are there?
Same question for 4 -digit primes with 4 distinct digits.
Bonus: Generalize for n distinct primes and digits. (n=2 to 7).
AFAIK - not in OEIS.
When I first read this puzzle, I thought it was an impossible enumeration task, thinking the categories would contain infinitely many examples, considering, for example, 1000211 to be an example of a prime with only three distinct digits: 0, 1 and 2. Then I realized a possible realistic interpretation: that no distinct digit appears more than once in the prime.
Those counts are:
No 10-digit primes use all ten digits as all such numbers are multiples of 9.
The counts for n = 1 to 7 were found by finding all the primes below 9999999 and categorizing them by length if they contained no duplicate digits. The counts for 8, 9 and 10 were found by permuting all the digits and testing the first 8, 9 or all, for primality. Care was taken to count the 8-digit numbers only once (digits 9 and 10, not used, in ascending order for the 8-digit number to be counted).
To make sure all permutations not beginning with zero were counted, the total permuations examined were 3265920 in number, which matches 10!-9!. I checked this as I took the shortcut of stopping the permuting once the string reached one beginning with zero, and I had to adjust the starting string so that no permutation would be lost.
Searching the sequence on the OEIS, I find in fact two occurrences of this sequence, one marked as merely the duplicate of another: A073532
(the original -- Number of n-digit primes with all digits distinct) and A098225 (the duplicate).
Dim crlf$, ct(10)
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
mform$ = a$
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
p = 2
s$ = LTrim(Str(p))
l = Len(s)
If l = 1 Then
ct(1) = ct(1) + 1
good = 1
For i = 2 To Len(s)
If InStr(s, Mid(s, i, 1)) < i Then good = 0: Exit For
If good Then ct(l) = ct(l) + 1
p = nxtprm(p)
Loop Until p > 9999999#
For i = 1 To 7
Text1.Text = Text1.Text & mform(i, "##") & mform(ct(i), "#######0") & crlf
s$ = "1023456789": h$ = s
p1 = Val(Left(s, 8))
If Mid(s, 9, 1) < Mid(s, 10, 1) Then
If prmdiv(p1) = p1 Then ct(8) = ct(8) + 1
p2 = Val(Left(s, 9))
If prmdiv(p2) = p2 Then ct(9) = ct(9) + 1
p3 = Val(s)
If prmdiv(p3) = p3 Then ct(10) = ct(10) + 1
tct = tct + 1
Loop Until Left(s, 1) = "0"
For i = 8 To 10
Text1.Text = Text1.Text & mform(i, "##") & mform(ct(i), "#########0") & crlf
Text1.Text = Text1.Text & tct & crlf
Dim n, dv, q
If num = 1 Then prmdiv = 1: Exit Function
n = Abs(num): If n > 0 Then limit = Sqr(n) Else limit = 0
If limit <> Int(limit) Then limit = Int(limit + 1)
dv = 2: GoSub DivideIt
dv = 3: GoSub DivideIt
dv = 5: GoSub DivideIt
dv = 7
Do Until dv > limit
GoSub DivideIt: dv = dv + 4 '11
GoSub DivideIt: dv = dv + 2 '13
GoSub DivideIt: dv = dv + 4 '17
GoSub DivideIt: dv = dv + 2 '19
GoSub DivideIt: dv = dv + 4 '23
GoSub DivideIt: dv = dv + 6 '29
GoSub DivideIt: dv = dv + 2 '31
GoSub DivideIt: dv = dv + 6 '37
If n > 1 Then prmdiv = n
q = Int(n / dv)
If q * dv = n And n > 0 Then
prmdiv = dv: Exit Function
n = x + 1
While prmdiv(n) < n Or n < 2
n = n + 1
nxtprm = n
Posted by Charlie
on 2018-10-06 11:28:05