https://github.com/letsdeepchat/recursive-digit-sum-problem-using-java
Recursive Digit Sum Problem We define super digit of an integer n using the following rules: Given an integer, we need to find the super digit of the integer n. If n has only 1 digit, then its super digit is n. Otherwise, the super digit of n is equal to the super digit of the sum of the digits of n. superDigit has the following parameter(s): string n: a string representation of an integer int k: the times to concatenate n to make p. Input The first line contains two space separated integers, n and k. Constraints: 1 <= n <= 10^100000 1 <= k <= 100000 Output In a new line, print the the super digit of n repeated k times. Example Input: 148 3 Output: 3 Explanation: Here n=148 and k=3 , so p=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) = super_digit(12) = super_digit(1+2) = super_digit(3) = 3
https://github.com/letsdeepchat/recursive-digit-sum-problem-using-java
Last synced: about 1 month ago
JSON representation
Recursive Digit Sum Problem We define super digit of an integer n using the following rules: Given an integer, we need to find the super digit of the integer n. If n has only 1 digit, then its super digit is n. Otherwise, the super digit of n is equal to the super digit of the sum of the digits of n. superDigit has the following parameter(s): string n: a string representation of an integer int k: the times to concatenate n to make p. Input The first line contains two space separated integers, n and k. Constraints: 1 <= n <= 10^100000 1 <= k <= 100000 Output In a new line, print the the super digit of n repeated k times. Example Input: 148 3 Output: 3 Explanation: Here n=148 and k=3 , so p=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) = super_digit(12) = super_digit(1+2) = super_digit(3) = 3
- Host: GitHub
- URL: https://github.com/letsdeepchat/recursive-digit-sum-problem-using-java
- Owner: letsdeepchat
- Created: 2021-12-25T13:37:10.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-25T13:40:00.000Z (over 4 years ago)
- Last Synced: 2025-02-12T15:40:48.958Z (about 1 year ago)
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Recursive-Digit-Sum-Problem-using-Java
Recursive Digit Sum Problem
We define super digit of an integer n using the following rules:
Given an integer, we need to find the super digit of the integer n.
If n has only 1 digit, then its super digit is n.
Otherwise, the super digit of n is equal to the super digit of the sum of the digits of n.
superDigit has the following parameter(s):
string n: a string representation of an integer
int k: the times to concatenate n to make p.
Input
The first line contains two space separated integers, n and k.
Constraints:
1 <= n <= 10^100000
1 <= k <= 100000
Output
In a new line, print the the super digit of n repeated k times.
Example
Input:
148 3
Output:
3
Explanation:
Here n=148 and k=3 , so p=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)
= super_digit(12)
= super_digit(1+2)
= super_digit(3)
= 3