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

Home > Numbers
Same digits (Posted on 2018-12-26) Difficulty: 3 of 5
What is the smallest multidigit prime, all its digits being distinct, such that its largest digit is the same as the largest digit of the sum of its digits?

See The Solution Submitted by Ady TZIDON    
Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 6
379 is the smallest

The first 100 satisfying the criterion are listed below with their respective SODs:

379  19
397  19
467  17
647  17
739  19
829  19
937  19
1279  19
1297  19
1367  17
1459  19
1549  19
1637  17
1693  19
2089  19
2179  19
2357  17
2539  19
2593  19
2719  19
2753  17
2791  19
2917  19
2953  19
2971  19
3079  19
3167  17
3169  19
3257  17
3259  19
3527  17
3529  19
3617  17
3671  17
3691  19
3709  19
3761  17
3907  19
4157  17
4159  19
4517  17
4519  19
4561  16
4591  19
4651  16
4751  17
4951  19
5147  17
5237  17
5273  17
5417  17
5419  19
5471  17
5623  16
5641  16
5741  17
5879  29
5897  29
5923  19
5987  29
6047  17
6173  17
6317  17
6451  16
7039  19
7129  19
7219  19
7253  17
7309  19
7451  17
7523  17
7541  17
7589  29
8209  19
8597  29
9127  19
9587  29
9613  19
9631  19
9721  19
9857  29
10369  19
10457  17
10459  19
10639  19
10729  19
12097  19
12347  17
12437  17
12473  17
12743  17
12907  19
13249  19
14057  17
14293  19
14327  17
14723  17
14879  29
14897  29
14923  19

DefDbl A-Z
Dim crlf$

Function mform$(x, t$)
  a$ = Format$(x, t$)
  If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
  mform$ = a$
End Function

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
 
 p = 11
 Do
   p = nxtprm(p)
   ps$ = LTrim(Str(p))
   good = 1: mx = 0: tot = 0: mxs = 0
   For i = 1 To Len(ps)
     If InStr(ps, Mid(ps, i, 1)) < i Then good = 0: Exit For
     dv = Val(Mid(ps, i, 1))
     tot = tot + dv
     If dv > mx Then mx = dv
   Next
   If good Then
     ss$ = LTrim(Str(tot))
     For i = 1 To Len(ss)
       If Val(Mid(ss, i, 1)) > mxs Then mxs = Val(Mid(ss, i, 1))
     Next
     If mxs = mx Then
       Text1.Text = Text1.Text & p & "  " & ss & crlf
       ct = ct + 1
       If ct = 100 Then Exit Do
     End If
   End If
   DoEvents
 Loop
 Text1.Text = Text1.Text & " done"
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

Function nxtprm(x)
  Dim n
  n = x + 1
  While prmdiv(n) < n Or n < 2
    n = n + 1
  Wend
  nxtprm = n
End Function


  Posted by Charlie on 2018-12-26 10:24:13
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 (10)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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