There are infinitely many ordered pairs
(m,n) of positive integers for which
m + (m+1) + (m+2) + ... (n-1) + n = mn.
List the first five pairs ordered by values of m.
(2m+(n-m))/2 * (n-m+1) = nm
(m+n)(n-m+1) = 2nm
mn - m^2 + m + n^2 - nm + n = 2nm
n^2 - m^2 + m + n - 2nm = 0
n^2 + (1-2m)n + m - m^2 = 0
so
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For m = 1 To 100000
b = 1 - 2 * m
c = m - m * m
det = b * b - 4 * c
If det >= 0 Then
s1 = (-b - Sqr(det)) / 2
s2 = (-b + Sqr(det)) / 2
If s1 > 0 And Abs(s1 - Int(s1)) < 0.000001 Then
Text1.Text = Text1.Text & m & Str(s1) & crlf
End If
If s2 > 0 And Abs(s2 - Int(s2)) < 0.000001 Then
Text1.Text = Text1.Text & m & Str(s2) & crlf
End If
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
producing these first eight pairs:
1 1
3 6
15 35
85 204
493 1189
2871 6930
16731 40391
97513 235416
|
Posted by Charlie
on 2015-12-04 11:27:37 |