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

Home > Numbers
Integer Triplets with a Difference (Posted on 2015-01-30) Difficulty: 2 of 5
Find three different triplets of consecutive integers such that the first term of each triplet is a numerical palindrome, the second a square, and the third a prime.

No Solution Yet Submitted by Danish Ahmed Khan    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 6 of 6 |
DefDbl A-Z
Dim wd(10) As String, w As String, sz, 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

 For n = 1 To 9999999
   ns$ = LTrim(Str(n))
   l = Len(ns$)
   s1$ = ns$
   For i = l To 1 Step -1
     s1$ = s1$ + Mid(ns$, i, 1)
   Next
   GoSub checkIt
   s1$ = ns$
   For i = l - 1 To 1 Step -1
     s1$ = s1$ + Mid(ns$, i, 1)
   Next
   GoSub checkIt
 Next n
 Text1.Text = Text1.Text & "done"
 Exit Sub
 
checkIt:
   sq = Val(s1$) + 1
   sr = Int(Sqr(sq) + 0.5)
   If sr * sr = sq Then
     pr = sq + 1
     If prmdiv(pr) = pr Then
       Text1.Text = Text1.Text & s1$ & Str(sq) & Str(pr) & crlf
       DoEvents
     End If
   End If
 Return

End Sub
Function prm(i)
  Dim p As Long
  Open "17-bit primes.bin" For Random As #111 Len = 4
  Get #111, i, p
  prm = p
  Close 111
End Function
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
    n = n + 1
  Wend
  nxtprm = n
End Function
 
finds only

3 4 5
99 100 101
575 576 577

The seven digits of n would allow for 14-digit palindromes to lead off the triplet, so it looks as if the three triplets are all there are.

Edited on January 30, 2015, 10:35 am
  Posted by Charlie on 2015-01-30 10:31:52

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 (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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