What is the smallest integer that can be presented as a sum of 2 squares of distinct integers in 7 different ways?
Assuming that, for example, 400+27225 is not considered different from 27225+400, 27625 is the smallest such integer and in fact has 8 different ways:
27625 8
400 + 27225
729 + 26896
2025 + 25600
3600 + 24025
6889 + 20736
7744 + 19881
10201 + 17424
13225 + 14400
For t = 2 To 1000000
For a = 1 To t / 2
DoEvents
b = t - a
n = a * a + b * b
If n <= 1000000 Then
numW(n) = numW(n) + 1
how(numW(n), n) = a
If numW(n) >= 7 Then
Text1.Text = Text1.Text & n & " " & numW(n) & crlf
End If
If numW(n) = 8 Then
For i = 1 To 8
Text1.Text = Text1.Text & " "
Text1.Text = Text1.Text & how(i, n) * how(i, n) & " "
r = n - how(i, n) * how(i, n)
Text1.Text = Text1.Text & r & crlf
Next
GoTo finsh
End If
If numW(n) > maxW Then maxW = numW(n): maxN = n
Else
Exit For
End If
Next
Next t
finsh:
Text1.Text = Text1.Text & "done"
If however a+b is not considered the same as b+a, the value of a would be allowed to go all the way to t-1 in the above code:
For a = 1 To t / 2
and the result would be:
1105 8
16 +1089
1089+ 16
81 +1024
1024+ 81
144 + 961
961 + 144
529 + 576
576 + 529
If you need exactly 7 (rather than 8):
31250 7
625 +30625
30625+ 625
5329 +25921
25921 + 5329
7225 +24025
24025 + 7225
15625 +15625
|
Posted by Charlie
on 2020-07-10 10:24:33 |