If space is not a restriction- Build a B-tree. 1. Have a dummy root. 2. At level one- Numbers divisible by 1. ie. (1-9). 3. At level 2- numbers made after adding a digit to numbers at level 1. e.g. number 7 at level will have children- (70,72,74,76,78). and so on.. 4. Do the same at each level. Leaf nodes at level 10 will be your answers.
I think math can optimize this a bit- though. On Thu, Jul 29, 2010 at 9:57 PM, amit <[email protected]> wrote: > An algorithm to print all the 10-digit nos such that first 1 digit is > divisible by 1, first 2 digits by 2, first 3 digits by 3 and so > on...first 9 digits by 9. I think the tenth digit can be anything from > 0 to 9. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
