This is my solution:

https://www.codechef.com/viewsolution/21149273

I have tried every possible case and it works but i am still getting WA…is there still any case im missing?

For the case N=7, D=32, does your solution return the pair *(1, 9)* – i.e. 1 is the result, 9 is the number of steps?

- Steps 1-6: 7 + 6 x 32 = 199.
- Steps 7, 8, 9: DigitSum(199) = 19. Then DigitSum(19) = 10. Then DigitSum(10) =
**1.**

There is another solution that reduces to 1 in **8** steps.

- Steps 1-3: 7 + 3 x 32 = 103.
- Step 4: DigitSum(103) = 4.
- Steps 5-7: 4 + 3 x 32 = 100.
- Step 8: DigitSum(100) =
**1.**

1 Like