Getting WA in OCTOBER CHALLENGE 2018-MINDSUM

My Solution:-https://www.codechef.com/viewsolution/20565223

After trying for many days during the contest with 100’s of test cases I was not able to get where I am wrong
So If anybody can identify it will be highly appreciated
Thanks

The Same mistake that i was doing…

Your program fails for N = 2 & D = 82 and some other cases :

Your Output = 1 11

Expected output = 1 10

Reason - 2 + 7*82 -> 576 -> 18 -> 18+82 -> 100 -> 1

Count = 7+1+1+1 = 10

Thanks for your answer.