TheAlgorithms-Python
42 строки · 827.0 Байт
1"""
2Problem 20: https://projecteuler.net/problem=20
3
4n! means n × (n − 1) × ... × 3 × 2 × 1
5
6For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
7and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
8
9Find the sum of the digits in the number 100!
10"""
11
12
13def solution(num: int = 100) -> int:14"""Returns the sum of the digits in the factorial of num15>>> solution(100)
16648
17>>> solution(50)
18216
19>>> solution(10)
2027
21>>> solution(5)
223
23>>> solution(3)
246
25>>> solution(2)
262
27>>> solution(1)
281
29"""
30fact = 131result = 032for i in range(1, num + 1):33fact *= i34
35for j in str(fact):36result += int(j)37
38return result39
40
41if __name__ == "__main__":42print(solution(int(input("Enter the Number: ").strip())))43