+ 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
9 ответов
+ 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
+ 3
SoloProg It should also be a multiple of 18 ,you are missing the logic
+ 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
+ 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
+ 1
You said "18-> 198 (smallest)-> sum = 18 "
I think the answer is 99 as it is the smallest number.
+ 1
Prabhas Koya
What about this?
https://code.sololearn.com/cmdhR01ry651/?ref=app
+ 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.
- 1
Please take a look at the forum rules:
https://www.sololearn.com/Content-Creation-Guidelines/
https://www.sololearn.com/Discuss/1316935/?ref=app
Take a look at these guides on how to ask a question.
https://stackoverflow.com/help/how-to-ask
https://www.sololearn.com/blog/38/8-simple-rules-to-get-help-from-the-community