File tree Expand file tree Collapse file tree 1 file changed +16
-14
lines changed
Expand file tree Collapse file tree 1 file changed +16
-14
lines changed Original file line number Diff line number Diff line change 77Otherwise, the super digit of x is equal to the super digit of the sum of the digits of .
88For example, the super digit 9875 of will be calculated as:
99
10- super_digit(9875) 9+8+7+5 = 29
11- super_digit(29) 2 + 9 = 11
12- super_digit(11) 1 + 1 = 2
13- super_digit(2) = 2
10+ super_digit(9875) 9+8+7+5 = 29
11+ super_digit(29) 2 + 9 = 11
12+ super_digit(11) 1 + 1 = 2
13+ super_digit(2) = 2
1414
1515
1616 ex -2:
1717 Here n=148 and k=3 , so p=148148148 .
1818
19- super_digit(P) = super_digit(148148148)
19+ super_digit(P) = super_digit(148148148)
2020 = super_digit(1+4+8+1+4+8+1+4+8)
2121 = super_digit(39)
2222 = super_digit(3+9)
2323 = super_digit(12)
2424 = super_digit(1+2)
2525 = super_digit(3)
2626 = 3
27- """
28-
27+ """
2928
3029"""
3130
37363
3837
3938"""
39+
40+
4041def superDigit (n , k ):
4142 # Calculate the initial sum of the digits in n
4243 digit_sum = sum (int (digit ) for digit in n )
43-
44+
4445 # Multiply the sum by k
4546 total_sum = digit_sum * k
46-
47+
4748 # Recursive function to find the super digit
4849 while total_sum >= 10 :
4950 total_sum = sum (int (digit ) for digit in str (total_sum ))
50-
51+
5152 return total_sum
5253
53- if __name__ == '__main__' :
54+
55+ if __name__ == "__main__" :
5456 first_multiple_input = input ().rstrip ().split ()
55-
57+
5658 n = first_multiple_input [0 ]
5759 k = int (first_multiple_input [1 ])
58-
60+
5961 result = superDigit (n , k )
60-
62+
6163 print (result )
You can’t perform that action at this time.
0 commit comments