What numbers N are the sum of a sequence of consecutive primes such that the product of the first and last numbers in the sequence is N?
2 * 5 = 10 = 2 + 3 + 5
3 * 13 = 39 = 3 + 5 + 7 + 11 + 13
5 * 31 = 155 = 5 + 7 + 11 + 13 + 17 + 19 + 23 + 29 + 31
7 * 53 = 371 = 7 + 11 + 13 + 17 + 19 + 23 + 29 + 31 + 37 + 41 + 43 + 47 + 53
The program has checked all primes up to the 201st prime, 1229. The highest prime actually used, 53, is the 16th prime.
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
For stp = 1 To 200
tot = prm(stp)
For lstp = stp + 1 To 201
tot = tot + prm(lstp)
If tot = prm(stp) * prm(lstp) Then
Text1.Text = Text1.Text & prm(stp) & " *" & Str(prm(lstp))
Text1.Text = Text1.Text & " = " & prm(stp) * prm(lstp) & " = "
For i = stp To lstp
Text1.Text = Text1.Text & Str(prm(i))
If i <> lstp Then Text1.Text = Text1.Text & " +"
Next
Text1.Text = Text1.Text & crlf
End If
DoEvents
Next
Next
Text1.Text = Text1.Text & prm(201) & " done"
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
|
Posted by Charlie
on 2018-07-04 12:48:06 |