mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-31 06:33:44 +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 .
|
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:
|
For example, the super digit 9875 of will be calculated as:
|
||||||
|
|
||||||
super_digit(9875) 9+8+7+5 = 29
|
super_digit(9875) 9+8+7+5 = 29
|
||||||
super_digit(29) 2 + 9 = 11
|
super_digit(29) 2 + 9 = 11
|
||||||
super_digit(11) 1 + 1 = 2
|
super_digit(11) 1 + 1 = 2
|
||||||
super_digit(2) = 2
|
super_digit(2) = 2
|
||||||
|
|
||||||
|
|
||||||
ex -2:
|
ex -2:
|
||||||
Here n=148 and k=3 , so p=148148148 .
|
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(1+4+8+1+4+8+1+4+8)
|
||||||
= super_digit(39)
|
= super_digit(39)
|
||||||
= super_digit(3+9)
|
= super_digit(3+9)
|
||||||
|
@ -24,8 +24,7 @@ super_digit(P) = super_digit(148148148)
|
||||||
= super_digit(1+2)
|
= super_digit(1+2)
|
||||||
= super_digit(3)
|
= super_digit(3)
|
||||||
= 3
|
= 3
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -37,25 +36,28 @@ Sample Output 0
|
||||||
3
|
3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def superDigit(n, k):
|
def superDigit(n, k):
|
||||||
# Calculate the initial sum of the digits in n
|
# Calculate the initial sum of the digits in n
|
||||||
digit_sum = sum(int(digit) for digit in n)
|
digit_sum = sum(int(digit) for digit in n)
|
||||||
|
|
||||||
# Multiply the sum by k
|
# Multiply the sum by k
|
||||||
total_sum = digit_sum * k
|
total_sum = digit_sum * k
|
||||||
|
|
||||||
# Recursive function to find the super digit
|
# Recursive function to find the super digit
|
||||||
while total_sum >= 10:
|
while total_sum >= 10:
|
||||||
total_sum = sum(int(digit) for digit in str(total_sum))
|
total_sum = sum(int(digit) for digit in str(total_sum))
|
||||||
|
|
||||||
return total_sum
|
return total_sum
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
first_multiple_input = input().rstrip().split()
|
first_multiple_input = input().rstrip().split()
|
||||||
|
|
||||||
n = first_multiple_input[0]
|
n = first_multiple_input[0]
|
||||||
k = int(first_multiple_input[1])
|
k = int(first_multiple_input[1])
|
||||||
|
|
||||||
result = superDigit(n, k)
|
result = superDigit(n, k)
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user