From 1d034b72433257e009a1d0c8a81fc038007449a2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:26:05 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- recursions/recursive_digit_sum.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/recursions/recursive_digit_sum.py b/recursions/recursive_digit_sum.py index 38ea37671..5b607ce13 100644 --- a/recursions/recursive_digit_sum.py +++ b/recursions/recursive_digit_sum.py @@ -7,16 +7,16 @@ If has only 1 digit, then its super digit is x . Otherwise, the super digit of x is equal to the super digit of the sum of the digits of . For example, the super digit 9875 of will be calculated as: - super_digit(9875) 9+8+7+5 = 29 - super_digit(29) 2 + 9 = 11 - super_digit(11) 1 + 1 = 2 - super_digit(2) = 2 + super_digit(9875) 9+8+7+5 = 29 + super_digit(29) 2 + 9 = 11 + super_digit(11) 1 + 1 = 2 + super_digit(2) = 2 ex -2: Here n=148 and k=3 , so p=148148148 . -super_digit(P) = super_digit(148148148) +super_digit(P) = super_digit(148148148) = super_digit(1+4+8+1+4+8+1+4+8) = super_digit(39) = super_digit(3+9) @@ -24,8 +24,7 @@ super_digit(P) = super_digit(148148148) = super_digit(1+2) = super_digit(3) = 3 - """ - +""" """ @@ -37,25 +36,28 @@ Sample Output 0 3 """ + + def superDigit(n, k): # Calculate the initial sum of the digits in n digit_sum = sum(int(digit) for digit in n) - + # Multiply the sum by k total_sum = digit_sum * k - + # Recursive function to find the super digit while total_sum >= 10: total_sum = sum(int(digit) for digit in str(total_sum)) - + return total_sum -if __name__ == '__main__': + +if __name__ == "__main__": first_multiple_input = input().rstrip().split() - + n = first_multiple_input[0] k = int(first_multiple_input[1]) - + result = superDigit(n, k) - + print(result)