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

Home > Numbers
Truncatable primes (Posted on 2018-07-15) Difficulty: 3 of 5
Take the prime number 3797. It has an interesting property. Remove continuously digits from the left, one by one, and it remains prime at each stage: 3797, 797, 97, and 7.

Similarly, we can work from right to left: 3797, 379, 37, and 3.

List the only eleven primes that are truncatable both from left to right and from right to left.

Rem: Each of 2, 3, 5, and 7 is considered a truncatable prime.

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 2
Here are 11 found by computer program:

23
313
3137
317
37
373
3797
53
73
739397
797

However, if we consider each of 2, 3, 5 and 7 to be considered a truncatable prime, then these are four more, making 15. Each is a prime, but actually if you truncate any one of these, nothing is left.

DefDbl A-Z
Dim p, crlf$

Private Sub Form_Load()
t = Timer
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True

 p = 2: addOn 2
 For firstOne = 3 To 7 Step 2
   p = firstOne
   addOn 2
 Next
 Text1.Text = Text1.Text & crlf & " done"
 
 
End Sub
Sub addOn(wh)
 For newdig = 1 To 9 Step 2
   p = 10 * p + newdig
 
   If prmdiv(p) = p Then
        If newdig <> 1 And newdig <> 9 Then
          dvsr = 10
          good = 1
          For c = 2 To wh - 1
            dvsr = 10 * dvsr
            q = Int(p / dvsr)
            tst = p - dvsr * q
            If prmdiv(tst) < tst Then good = 0: Exit For
          Next
          If good Then
            Text1.Text = Text1.Text & p & crlf
            DoEvents
          End If
        End If ' newdig not  1 or 9
        addOn wh + 1
   End If
   p = p \ 10
 Next newdig
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-07-15 19:20:58
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (4)
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