+ 3

Find out the smallest number that has its digits sum equal to a number.

Hello Solo Learn! I was trying to solve this problem: There are 2 numbers: S and K. Find out the smallest number A that has its digits sum equal to S. Also write A%K. I am trying to solve this problem for 2 hours, but i can't. I was wondering if you can help me! Thank you for time, and sorry if there are spelling mistakes, or grammars ones. Note: The program must be done in c++, or you can just tell me the idea, and i will try to apply it.

21st Oct 2017, 2:18 PM
Stefan Secrieru
Stefan Secrieru - avatar
4 Respuestas
+ 3
21st Oct 2017, 5:01 PM
Kartik
Kartik - avatar
+ 13
I think you've missed our the relation of K. Regarding A, you can always start with a largest possible digit from the right and do the same for the remaining digits by appending to the left to get the corresponding digit sum.
21st Oct 2017, 4:42 PM
Zephyr Koo
Zephyr Koo - avatar
+ 3
Thank you very much for your help Kartik Krishnan and Zephyr Koo. You helped me a lot. If i look at your code Kartik, it was more simple than i thought, but i just couldn't find the solution. Thank you very much again! Goodbye! I owe you this one. ;)
21st Oct 2017, 5:31 PM
Stefan Secrieru
Stefan Secrieru - avatar
+ 2
Glad I could help...
21st Oct 2017, 6:04 PM
Kartik
Kartik - avatar