Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
- #Find the sum of all numbers which are equal to the sum of the factorial of
- #their digits.
- #Note: as 1! = 1 and 2! = 2 are not sums they are not included.
- #A factorion is a natural number that equals the sum of the
- #factorials of its decimal digits.
- #Upper Bound: 1,854,721
- #Source: http://en.wikipedia.org/wiki/Factorion
- def fact(n):
- if n == 1 or n == 0:
- return 1
- return n*fact(n-1)
- def digitsFacSum(n):
- digitsStr = str(n)
- count = 0
- for i in digitsStr:
- count += fact(int(i))
- return count
- limit = 1854721
- count = 0
- for i in range(3,limit+1):
- if digitsFacSum(i) == i:
- count += i
- print count
Advertisement
Add Comment
Please, Sign In to add comment