Given a number n and a number d, we can add d to n as many times ( even 0 is possible ). The task is to find the minimum possible digit sum we can achieve by performing above operation.
Digit Sum is defined as the sum of digits of a number recursively until it is less than 10.
Input: n = 2546, d = 124 Output: 1 2546 + 8*124 = 3538 DigitSum(3538)=1 Input: n = 123, d = 3 Output: 3
- First observation here is to use %9 approach to find minimum possible digit sum of a number n. If modulo with 9 is 0 return 9 else return the remainder.
- Second observation is, a+d*(9k+l) modulo 9 is equivalent to a+d*l modulo 9, therefore, the answer to the query will be available in either no addition or first 8 additions of d, after which the digit sum will repeat.
Below is the implementation of above approach:
Minimum possible digitsum is :1
- Find the remainder when First digit of a number is divided by its Last digit
- Find the Number which contain the digit d
- Find nth number that contains the digit k or divisible by k.
- Program to find last digit of n'th Fibonnaci Number
- Find last five digits of a given five digit number raised to power five
- Count of Numbers in Range where first digit is equal to last digit of the number
- Largest number less than N with digit sum greater than the digit sum of N
- Find minimum number to be divided to make a number a perfect square
- Find minimum sum of factors of number
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Find the winner by adding Pairwise difference of elements in the array until Possible
- Find minimum number of coins that make a given value
- Find the minimum number of steps to reach M from N
- Find minimum number of Log value needed to calculate Log upto N
- Find the minimum number of rectangles left after inserting one into another
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.