An excellent number n has an even number of digits and, if you split the number into the front half a and the back half b, then b^2 − a^2 = n.
For example, 3468 = 68^2 − 34^2.
The only two-digit excellent number is 48 and the only four-digit
excellent number is 3468.
There are eight six-digit excellent numbers.
List them.
Bonus: List all 10-digit excellent numbers.
Source: Project Euler.
140400
190476
216513
300625
334668
416768
484848
530901
16604400
33346668
59809776
3333466668
4848484848
4989086476
from
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For i = 100000 To 999999
i2 = i Mod 1000
i1 = (i - i2) / 1000
If i2 * i2 - i1 * i1 = i Then Text1.Text = Text1.Text & i & crlf
DoEvents
Next
For i = 10000000 To 99999999
i1 = Int(i / 10000)
i2 = i - 10000 * i1
If i2 * i2 - i1 * i1 = i Then Text1.Text = Text1.Text & i & crlf
DoEvents
Next
For i = 1000000000 To 9999999999#
i1 = Int(i / 100000)
i2 = i - 100000 * i1
If i2 * i2 - i1 * i1 = i Then Text1.Text = Text1.Text & i & crlf
DoEvents
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
|
Posted by Charlie
on 2017-04-08 12:17:11 |