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
while S:
S, r = S//d, S%d
ans.append(r)
d += 1
return ans
S = 120
print factrep(S)
SF = 0
for i, c in enumerate(factrep(S)):
SF += c * factorial(i+1)
print S == SF
Christophe.
2013/11/14 Anthony Wickstead <[email protected]>
> 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*factorial(i)
>
> i-=1
>
> return ans
>
>
>
> Tony Wickstead
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Juan Grados
> *Sent:* 13 November 2013 21:45
> *To:* sage-support
> *Subject:* [sage-support] Factorial Carry Value in Python
>
>
>
> Let be s between 1 and l!-1 an integer value then s can expressed uniquely
> than:
>
>
>
> s = u1*(l-1)! + u2*(l-2)!+ ... ul*0
>
>
>
> Is there any function to find the values u1, u2, ..., ul in SAGE or python?
>
>
>
> --
> ---------------------------------------------------------------------
> MSc. Juan del Carmen Grados Vásquez
> Laboratório Nacional de Computação Científica
> Tel: +55 24 2233-6260
>
> (http://www.lncc.br/)
> http://juaninf.blogspot.com
> ---------------------------------------------------------------------
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.