Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We define super digit of an integer x using the following rules: Given an integer, we need to find the super digit of the integer.
We define super digit of an integer x using the following rules:
Given an integer, we need to find the super digit of the integer.
If x has only 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 x
For example, the super digit of will be calculated as:
superdigit
superdigit
superdigit
superdigit
Example
n
k
The number p is created by concatenating the string n k times so the initial p
superDigitp superDigit
superDigitp superDigit
superDigitp superDigit
All of the digits of p sum to The digits of sum to is only one digit, so it is the super digit.
Function Description
Complete the function superDigit in the editor below. It must return the calculated super digit as an integer.
superDigit has the following parameters:
string n: a string representation of an integer
int k: the times to concatenate n to make p
Returns
int: the super digit of n repeated k times
Input Format
The first line contains two space separated integers, n and k
Constraints
n
k
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started