OFFSET
0,1
COMMENTS
Numbers n for which a(n)=1 are called factorions (A014080).
Apart from factorions, only 3 cycles exist:
169 -> 363601 -> 1454 -> 169, so a(169) = a(363601) = a(1454) = 3.
871 -> 45361 -> 871, so a(871) = a(45361) = 2.
872 -> 45362 -> 872, so a(872) = a(45362) = 2.
All other n produce a chain reaching either a factorion or a cycle.
LINKS
Philippe Guglielmetti, Table of n, a(n) for n = 0..1000
S. S. Gupta, Sum of the factorials of the digits of integers, The Mathematical Gazette, 88-512 (2004), 258-261.
Project Euler, Problem 74: Digit factorial chains
EXAMPLE
For n = 4, 4!=24, 2!+4!=26, 2!+6!=722, 7!+2!+2!=5044, 5!+0!+4!+4!=169, 1!+6!+9!=363601, 3!+6!+3!+6!+0!+1!=1454, then 1!+4!+5!+4!=169 which already belongs to the chain, so a(4) = length of [4, 24, 26, 722, 5044, 169, 363601, 1454] = 8.
MATHEMATICA
Array[Length@ NestWhileList[Total@ Factorial@ IntegerDigits@ # &, #, UnsameQ, All, 100, -1] &, 68, 0] (* Michael De Vlieger, May 10 2018 *)
PROG
(Python)
for n in count(0):
l=[]
i=n
while i not in l:
l.append(i)
i=sum(map(factorial, map(int, str(i))))
print(n, len(l))
(PARI) f(n) = if (!n, n=1); my(d=digits(n)); sum(k=1, #d~, d[k]!);
a(n) = {my(v = [n], vs = Set(v)); for (k=1, oo, new = f(n); if (vecsearch(vs, new), return (#vs)); v = concat(v, new); vs = Set(v); n = new; ); } \\ Michel Marcus, May 18 2018
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Philippe Guglielmetti, May 03 2018
STATUS
approved