+ 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.
4 Antworten
+ 3
Is this what you were after???
https://code.sololearn.com/cSY5LWpNxAag/?ref=app
+ 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.
+ 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. ;)
+ 2
Glad I could help...