All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
All digits distinct (Posted on 2018-12-12) Difficulty: 2 of 5
What is the highest prime number with no repeated digits?

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 2 of 2 |
The largest prime with no repeated digits is

987654103

It couldn't have 10 digits, as that would be a number divisible by 9, so a digit not divisible by 3 had to be removed to make it indivisible by 3. To give it the maximal number of remaining digits it needed a zero to give it nine full digits, but not at either the end nor the beginning.

The answer does indeed lack the digit 2, and has its zero in the second to last position. All the candidates were tested by 

DefDbl A-Z
Dim crlf$

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 
 s$ = "123456789": h$ = s
 Do
   If Val(Right(s, 1)) Mod 3 <> 0 Then
     s1$ = Left(s, 8)
     For p = 1 To 7
       s2$ = Left(s1, p) + "0" + Mid(s1, p + 1)
       v = Val(s2)
       pd = prmdiv(v)
       If pd = v Then
          If v > mx Then mx = v
       End If
     Next
   End If
   DoEvents
   permute s
 Loop Until s = h
 
 Text1.Text = mx
 
 Form1.Visible = True
End Sub
 
Function prmdiv(num)
 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
 Loop
 If n > 1 Then prmdiv = n
 Exit Function

DivideIt:
 Do
  q = Int(n / dv)
  If q * dv = n And n > 0 Then
    prmdiv = dv: Exit Function
   Else
    Exit Do
  End If
 Loop

 Return
End Function

  Posted by Charlie on 2018-12-12 15:15:17
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2019 by Animus Pactum Consulting. All rights reserved. Privacy Information