#!/usr/bin/env python from math_tools import factorial, digits """https://projecteuler.net/problem=20""" if __name__ == "__main__": print sum(digits(factorial(100)))
#!/usr/bin/env python from math_tools import factorial, digits """https://projecteuler.net/problem=34""" if __name__ == "__main__": upper_bound_coef = 1 while len(str(upper_bound_coef * factorial(9))) > upper_bound_coef: upper_bound_coef += 1 result = 0 for n in range(10, upper_bound_coef * factorial(9)): if sum(factorial(i) for i in digits(n)) == n: result += n print(result)
#!/usr/bin/env python from math_tools import factorial, digits """https://projecteuler.net/problem=34""" if __name__ == '__main__': upper_bound_coef = 1 while len(str(upper_bound_coef * factorial(9))) > upper_bound_coef: upper_bound_coef += 1 result = 0 for n in range(10, upper_bound_coef * factorial(9)): if sum(factorial(i) for i in digits(n)) == n: result += n print(result)
#!/usr/bin/env python from math_tools import factorial, digits """https://projecteuler.net/problem=20""" if __name__ == '__main__': print sum(digits(factorial(100)))
# coding: utf8 """ n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. Find the sum of the digits in the number 100! """ from math_tools import factorial num = factorial(100) print sum(map(int, str(num)))