Find all solutions of the system
s(x) + s(y) = x
x + y + s(z) = z
s(x) + s(y) + s(z) = y − 4,
where x, y and z are positive integers, and each of s(x), s(y) and s(z) denotes the sum of digits of
x, y and z, respectively, in decimal notation.
x y z
18 27 50
18 36 68
found by
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For z = 5 To 10000
sodz = sod(z)
xplusy = z - sodz
For x = 1 To xplusy - 1
DoEvents
y = xplusy - x
sodx = sod(x): sody = sod(y)
If sodx + sody = x Then
If x + sodz = y - 4 Then
Text1.Text = Text1.Text & x & Str(y) & Str(z) & crlf
End If
End If
Next
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Function sod(n)
s$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(s$)
tot = tot + Val(Mid(s$, i, 1))
Next
sod = tot
End Function
Edited on March 19, 2017, 11:38 am
|
Posted by Charlie
on 2017-03-19 11:38:14 |