Project Euler #88: Product-sum numbers

  • + 1 comment

    Is there any non-recursive approach out there? The recursive version loops through candidates in such a way that answers are updated occasionally (an answer you find midway might be replaced by another at the end of the day).

    I tried to use a dequeue and set to generate multiplicative partitions (based on a list of primitive factors) of ascending n, and whenever any answer is found it is guaranteed to be one of the final answers. It seems to be correct but was too slow for half of the test cases. I don't know if it is because of the algorithm itself which is poor in nature, or the extensive use and manipulation of list and set in this case.

    This is the difference between constructing products from ascending factors and constructing factors from ascending products. Well, after all the former approach sounds a lot more straightforward.