A palindromic number, below 2000, thrice a square, is the sum of nine consecutive primes.
Enough said.
What number(s) complies(comply)?
This checks all sums of 9 successive primes until the sum exceeds 2000:
DefDbl A-Z
Dim crlf$, pr(9)
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
pno = 1
For i = 1 To 9
pno = nxtprm(pno)
pr(i) = pno
Sum = Sum + pno
Next
Do
s$ = LTrim(Str(Sum))
good = 1
For i = 1 To Len(s$) / 2
If Mid(s$, i, 1) <> Mid(s$, Len(s$) + 1 - i, 1) Then good = 0: Exit For
Next
If good Then
sq = Sum / 3
If sq = Int(sq) Then
sr = Int(Sqr(sq) + 0.5)
If sr * sr = sq Then
Text1.Text = Text1.Text & s & " ="
For i = 1 To 9
Text1.Text = Text1.Text & " +" & Str(pr(i))
Next i
Text1.Text = Text1.Text & crlf
DoEvents
End If
End If
End If
Sum = Sum - pr(1)
For i = 1 To 8
pr(i) = pr(i + 1)
Next
pr(9) = nxtprm(pr(8))
Sum = Sum + pr(9)
Loop Until Sum > 2000
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
n = n + 1
Wend
nxtprm = n
End Function
It finds only
363 = + 23 + 29 + 31 + 37 + 41 + 43 + 47 + 53 + 59
It finds no other solutions even when totals through 200,000 are checked (highest prime 22277).
|
Posted by Charlie
on 2015-01-19 11:47:55 |