What is the only number equal to the sum of
subfactorials of its digits?
Hint: it is below 150000
This fact was discovered by Malachy in 1979.
The subfactorials of single digits are:
0 1
1 0
2 1
3 2
4 9
5 44
6 265
7 1854
8 14833
9 133496
The desired answer:
148349 148349
shown as the number itself and the sum of the subfactorials of its digits.
found by
DefDbl A-Z
Dim crlf$, subfact As Variant
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
subfact = Array(1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496)
For i = 0 To 9
Text1.Text = Text1.Text & i & " " & subfact(i) & crlf
Next
For n = 1 To 150000
ns$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(ns)
tot = tot + subfact(Val(Mid(ns, i, 1)))
Next
If tot = n Then Text1.Text = Text1.Text & crlf & n & Str(tot) & crlf
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Edited on February 25, 2018, 11:54 am
|
Posted by Charlie
on 2018-02-25 11:54:05 |