What is the smallest number that can be written as the difference of 2 squares in 4 ways?
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
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
Open "4ways.txt" For Output As #2
For a = 1 To 1000
For b = a + 1 To 1000
diff = b * b - a * a
Print #2, mform(diff, "#########0") + mform(a, "#####0") + mform(b, "#####0")
Next
Next
Close
Shell "sort < 4ways.txt > 4wayssorted.txt "
Open "4wayssorted.txt" For Input As #1
Do
p3$ = p2$
p2$ = p$
p$ = l$
Line Input #1, l$
If Left(l$, 10) = Left(p$, 10) Then
If Left(p$, 10) = Left(p2$, 10) Then
If Left(p2$, 10) = Left(p3$, 10) Then
Text1.Text = Text1.Text & p3$ + crlf
Text1.Text = Text1.Text & p2$ + crlf
Text1.Text = Text1.Text & p$ + crlf
Text1.Text = Text1.Text & l$
If psol$ = Left$(l$, 10) Then
Text1.Text = Text1.Text & "***" + crlf + crlf
Else
Text1.Text = Text1.Text & crlf + crlf
End If
DoEvents
psol$ = Left(l$, 10)
If Val(psol$) > 1500 Then Exit Do
End If
End If
End If
Loop Until EOF(1)
End Sub
finds 96 as the answer, and further, for n = b^2 - a^2 (abbreviated here):
n a b
96 2 10
96 5 11
96 10 14
96 23 25
105 4 11
105 8 13
105 16 19
105 52 53
120 1 11
120 7 13
120 13 17
120 29 31
135 3 12
135 11 16
135 21 24
135 67 68
144 5 13
144 9 15
144 16 20
144 35 37
. . .
192 2 14
192 8 16
192 13 19
192 22 26
192 47 49 *** the first one with 5 ways
. . .
240 4 16
240 7 17
240 11 19
240 17 23
240 28 32
240 59 61 *** the first with 6 ways
. . .
480 2 22
480 7 23
480 14 26
480 19 29
480 26 34
480 37 43
480 58 62
480 119 121 *** the first with over 6 ways (it's 8 ways)
. . .
720 3 27
720 8 28
720 11 29
720 24 36
720 31 41
720 41 49
720 57 63
720 88 92
720 179 181 *** first with 9 ways
. . .
960 1 31
960 8 32
960 14 34
960 22 38
960 34 46
960 43 53
960 56 64
960 77 83
960 118 122
960 239 241 *** ten ways
. . .
1440 2 38
1440 9 39
1440 18 42
1440 26 46
1440 31 49
1440 37 53
1440 54 66
1440 67 77
1440 86 94
1440 117 123
1440 178 182
1440 359 361 *** over 10 (is 12)
. . .
Edited on June 5, 2014, 9:51 am
|
Posted by Charlie
on 2014-06-04 18:02:26 |