Since the limit is so small, won't a simple bruteforce do ? Just run a loop from [100, 1000) and return the minimum.
Here is a quick python code I wrote. >>> N = 24 >>> min (i for i in range (100, 1001) if int (str (i) [0]) * int (str (i) [1]) * int (str (i) [2]) == N) 138 >>> N = 36 >>> min (i for i in range (100, 1001) if int (str (i) [0]) * int (str (i) [1]) * int (str (i) [2]) == N) 149 >>> N = 100 >>> min (i for i in range (100, 1001) if int (str (i) [0]) * int (str (i) [1]) * int (str (i) [2]) == N) 455 On Wed, Feb 12, 2014 at 8:45 PM, atul anand <[email protected]> wrote: > Given a number N, find the smallest 3 digits number such that product of > its digits is equal to N. > > For Eg:- > > for input 24 , output :138 (1*3*8 = 24) > for input 36 , output :149 (1*4*9 = 36) > for input 100 , output : 455 (4*5*5 = 100) > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
