Challenge[unsolved] HELP | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Challenge[unsolved] HELP

For a input n find the smallest number whose sum of digits is n and is a multiple of n. I found this interesting and I am trying to get an efficient way for LARGER NUMBERS I am not able to reach far. How can I do? Ex- 18-> 198 -> sum = 18 and is a multiple of 18 and smallest https://code.sololearn.com/c8AzOi0yh4AH/?ref=app

29th Nov 2021, 8:39 AM
Prabhas Koya
9 Answers
+ 3
SoloProg thanks, for your answer, I needed the number not just whose sum of digits is equal to n but also the number should be a multiple of n ... Ex- 18-> 198 (smallest)-> sum = 18 and a multiple of 18 21->399(smallest)-> sum= 21 and a multiple of 21 THE CODE SHOULD HANDLE LARGE NUMBERS
29th Nov 2021, 11:00 AM
Prabhas Koya
+ 3
SoloProg It should also be a multiple of 18 ,you are missing the logic
29th Nov 2021, 3:11 PM
Prabhas Koya
+ 2
Find the smallest number whose sum of digits is N https://www.geeksforgeeks.org/find-the-smallest-number-whose-sum-of-digits-is-n Find the smallest number whose digits multiply to a given number n https://www.geeksforgeeks.org/find-smallest-number-whose-digits-multiply-given-number-n # Keep learning & happy coding :D https://code.sololearn.com/cfzT9WoDUOH5
29th Nov 2021, 10:24 AM
SoloProg
SoloProg - avatar
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ thanks for responding. In your code It just moves by one number at a time from 1 , in this way it takes long to move even until it's multiples(which is one the condition that the number must be a multiple) ( my code just moves over multiples and not just every multiple consecutively it jumps over when needed. (but here the jumping is not certain as I don't get the perfect logic how to jump multiples instead of searching consecutively, yet I thought of some small logic and placed the coditions) ) I hope you can get the logic
29th Nov 2021, 4:21 PM
Prabhas Koya
+ 1
You said "18-> 198 (smallest)-> sum = 18 " I think the answer is 99 as it is the smallest number.
29th Nov 2021, 2:58 PM
SoloProg
SoloProg - avatar
29th Nov 2021, 3:22 PM
A͢J
A͢J - avatar
+ 1
Prabhas Koya You can jump numbers by initialising i with input then add input in i after every iteration like: number = int(input()) i = number i += number You can see in shared code.
30th Nov 2021, 2:52 PM
A͢J
A͢J - avatar