Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
For a given positive integer number N, write a complete program to find the minimal natural M such that the product of digits of M is equal N. N is less than 1,000,000,000. If no M exists, print -1. Your code should not take more than 10 secs for any case.

Sample Inputs
1
3
15
10
123456789
32
432
1296

Sample Outputs
1
3
35
25
-1
48
689
2899


Please help with the code!

Thank you in advance.
Posted
Updated 3-Jul-11 2:33am
v2

We don't do homework for people - not because we feel like we're elite or too important, but because YOU won't learn anything if we do it for you. If you try to do it and have a problem with a particular part of the code, come back here and ask a question about THAT particular part of the code - NOT the entire application. If you don't learn these basic/essential skills now, you may as well decide on another career path before you put another - BETTER - programmer out of work simply because of your lower salary requirements.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Jul-11 13:16pm    
Agree, a 5. Also, the problems sounds very boring -- who would be interested to waste time on it?
--SA
#realJSOP 3-Jul-11 14:11pm    
It seems I have to type that answer at least two-three times every week. This morning, I created a web page on my site that I can just link to. :)

Beyond that, programming is - more often than not - often littered with boring tasks. :)
Sergey Alexandrovich Kryukov 3-Jul-11 16:37pm    
Boring task becomes less boring when it is well-paid :-)
I hardly imaging volunteering to solve boring task for no appreciation though -- this is the difference.
--SA
Hi,

I got your logic, first you find out all the factors of the given input number. Always take the factors of single digits and find the best combination of factors which will give product of those as given input, as well as form the minimal number with those numbers.
 
Share this answer
 
Comments
[no name] 18-Aug-14 7:48am    
Do you think that he is still interested since his homework assignment was due 3 years ago?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900