mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
208b741003
commit
1d034b7243
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user