A factorion is a number that equals the sum of the factorials of its decimal digits, e.g. 145 is a factorion because 1! + 4! + 5! = 1 + 24 + 120 = 145.
There are exactly four (in base 10) such numbers;
1, 2, 145, and the last one is for you to find.
Bonus task: Determine all numbers such that the sum of factorials of their digits - expressed in any imaginable base- is exactly the same regardless of the base chosen.
1
2
145
40585
DefDbl A-Z
Dim crlf$, fact(9)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
fact(0) = 1
For i = 1 To 9
fact(i) = i * fact(i - 1)
Next
For n = 1 To 9999999
ns$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(ns)
tot = tot + fact(Val(Mid(ns, i, 1)))
Next
If tot = n Then
Text1.Text = Text1.Text & n & crlf
End If
DoEvents
Next n
Text1.Text = Text1.Text & crlf & " done"
End Sub
|
Posted by Charlie
on 2015-10-19 14:42:49 |