Hello,
I would do it like that. I think that in the question the 0! must be change
to 1!.
_ = """
S = u_1*(n - 1)! + u_2*(n - 2)! + ... + u_{n - 2}*2! + u_{n - 1}*1!
S = [[ ... [[u_1*(n - 1) + u_2]*(n - 2)] + ... + u_{n - 2}] ... ]]*2 +
u_{n - 1}
"""
def factrep(S):
ans = []
d = 2
I know of nothing built in to Sage, but this is easy to write. The following
seems to work, even if it isn't very elegant:
def factrep(nn):
n=nn
i=1
while factorial(i)<=n:
i+=1
i-=1
ans=[]
while i>0:
d=n//factorial(i)
ans.append(d)
n-=d*fact