 All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars  perplexus dot info  A rare palindrome (Posted on 2017-03-18) 64446 = 32213 + 32233
&
64446 = 33223 + 31223

This is the smallest example of a palindromic number S that is a sum of two consecutive primes and on the other hand equals the sum of the reversals of those two primes (also primes, albeit not consecutive).

Please provide another sample(s) with such peculiar feature.

 No Solution Yet Submitted by Ady TZIDON No Rating Comments: ( Back to comment list | You must be logged in to post comments.) computer solution Comment 1 of 1
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

Text1.Text = ""
crlf\$ = Chr(13) + Chr(10)
Form1.Visible = True

p = 2
Do
newp = nxtprm(p)
tot = p + newp
st\$ = LTrim(Str(tot))
good = 1
For i = 1 To Len(st) / 2
If Mid(st, i, 1) <> Mid(st, Len(st) + 1 - i, 1) Then good = 0: Exit For
Next
If good Then
st1\$ = LTrim(Str(p)): st2\$ = LTrim(Str(newp))
st1r\$ = ""
For i = 1 To Len(st1)
st1r\$ = Mid(st1, i, 1) + st1r
Next
st2r\$ = ""
For i = 1 To Len(st2)
st2r\$ = Mid(st2, i, 1) + st2r
Next
r1 = Val(st1r): r2 = Val(st2r)
If r1 + r2 = tot Then
If prmdiv(r1) = r1 And prmdiv(r2) = r2 Then
Text1.Text = Text1.Text & p & Str(newp) & "    " & tot & Str(r1) & Str(r2) & crlf
End If
End If
End If
DoEvents
oldp = p: p = newp
If p = 32213 Then
xx = xx
End If
Loop

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 Or n < 2
n = n + 1
Wend
nxtprm = n
End Function

shows the two successive primes and their palindromic total, followed by the reversed values that are also prime.

The first two below are trivial 1-digit primes with a 1-digit "palindrome" each. The next is the case given in the puzzle, and then comes the sought answer,

132,040,201 + 132,040,261 = 264,080,462 with the reverse primes being 102,040,231 and 162,040,231.

2 3    5 2 3
3 5    8 3 5
32213 32233    64446 31223 33223
132040201 132040261    264080462 102040231 162040231

The program was manually terminated at a point when the lower prime being checked was 1,387,665,827.

 Posted by Charlie on 2017-03-18 13:48:46 Please log in:

 Search: Search body:
Forums (0)