The number 1987 can be written as a three digit number xyz in some base
b.
If x + y + z = 1 + 9 + 8 + 7=25, determine all possible values of x, y, z, b.
Source: 1987 Canadian Mathematical Olympiad.
(In reply to
computer soln by Steven Lord)
DefDbl A-Z
Dim crlf$, dig(10)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
n = 1987: tot = 25
For bs = 10 To 5000
If base(n, bs) = 3 Then
t = 0
For i = 0 To base(n, bs) - 1
t = t + dig(i)
Next
If t = tot Then
For i = 2 To 0 Step -1
Text1.Text = Text1.Text & Str(dig(i))
Next
Text1.Text = Text1.Text & Str(bs) & crlf
End If
ElseIf Len(s) < 3 Then
Exit For
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Function base(n, b)
n2 = n
p = 0
Do
d = n2 Mod b
n2 = n2 \ b
dig(p) = d
p = p + 1
Loop Until n2 = 0
base = p
End Function
The program stopped (exited the loop) when the number of digits became less than 3 so did not require figuring the limit of the base
So no solution was given beyond:
being the three digits and the base, each expressed in decimal.
|
Posted by Charlie
on 2018-10-17 11:39:24 |