Given a digital root ‘D’ and number of digits ‘K’. The task is to print a number containing K digits that has its digital root equal to D. Print ‘-1’ if such a number does not exist.
Input: D = 4, K = 4 Output: 4000 No. of digits is 4. Sum of digits is also 4. Input: D = 0, K = 1 Output: 0
Approach: A key observation to solving this problem is that appending any number of 0s to a number does not change its digital root. Hence D followed by (K-1) 0’s is a simple solution.
Special case when D is 0 and K is not 1 does not have a solution since the only number with digital root 0 is 0 itself.
Below is the implementation of the above approach:
Time complexity: O(K)
- Digital Root (repeated digital sum) of the given large integer
- Smallest root of the equation x^2 + s(x)*x - n = 0, where s(x) is the sum of digits of root x.
- Sudo Placement[1.7] | Greatest Digital Root
- Print a number strictly less than a given number such that all its digits are distinct.
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Minimum number of digits to be removed so that no two consecutive digits are same
- Find the Largest number with given number of digits and sum of digits
- Find smallest number with given number of digits and sum of digits
- Smallest number with given sum of digits and sum of square of digits
- N-th root of a number
- Square root of a number using log
- Print numbers with digits 0 and 1 only such that their sum is N
- Find cubic root of a number
- Print last k digits of a^b (a raised to power b)