Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fact(n):
- if n == 1:
- return n
- else: return fact(n - 1) * n
- def listtoint(n):
- n = ''.join(list(map(str, n)))
- return int(n)
- def NextPermutation(p):
- i = len(p) - 2
- while i >= 0 and p[i] > p[i + 1]:
- i -= 1
- if i < 0:
- p[:] = []
- return
- j = len(p) - 1
- while p[j] < p[i]:
- j -= 1
- p[i], p[j] = p[j], p[i]
- p[i + 1:] = p[:i:-1]
- n = input()
- s = list(n)
- x = int(n)
- for i in range(fact(len(n))):
- NextPermutation(s)
- if s != []:
- x += listtoint(s)
- print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement