The sum of the first m integers is
m(m+1)/2
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
sqs = 0
For n = 1 To 9999999
sqs = sqs + n * n
mp = Sqr(sqs * 2)
m = Int(mp)
If m * (m + 1) / 2 = sqs Then
Text1.Text = Text1.Text & n & Str(m) & " " & Str(sqs) & crlf
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sums the first n squares and attempts to find an m that will work.
The results are
n m sums
1 1 1
5 10 55
6 13 91
85 645 208335
2696556 3615502423 6.53592888716719E+18
4432596 7619766609 2.90304215916256E+19
4767069 8498290955 3.61104745821666E+19
6506645 13551584866 9.18227261969759E+19
8888711 21637774295 2.340966382315E+20
9936291 25573540422 3.27002984870621E+20
In the cases above n=85, m=645, the results are probably spurious, as the sum of the squares exceeds the precision available with double-precision floating point.
This points to 85 being the largest n for which this is possible.
|
Posted by Charlie
on 2016-04-11 15:49:43 |