Skip to content

Instantly share code, notes, and snippets.

  • Save Denenberg/483055435170052e0148bd9b44696e16 to your computer and use it in GitHub Desktop.
Save Denenberg/483055435170052e0148bd9b44696e16 to your computer and use it in GitHub Desktop.
Последовательность A349597 задаётся по следующему правилу: a(n) is the sum of digits of a(n-1)! with a(1) = 3.
# Последовательность A349597 задаётся по следующему правилу:
# a(n) is the sum of digits of a(n-1)! with a(1) = 3.
import sys
def factorial(n):
result = 1
for i in range(2, n + 1):
result *= i
return result
def sum_of_digits(n):
return sum(int(digit) for digit in str(n))
def a(n, a_prev=3):
result = a_prev
for i in range(2, n + 1):
result = sum_of_digits(factorial(result))
return result
sys.setrecursionlimit(1000)
for i in range(1, 10):
print(a(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment