Last active
February 7, 2023 00:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Последовательность 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