A number as it's prime number parts

前端 未结 3 2060
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 12:23

I have to print the number of ways you can represent a given number as it\'s prime number parts.

Let me clarify: Let\'s say I have been given this number 7. Now, fir

3条回答
  •  既然无缘
    2020-12-19 13:20

    Dynamic programming is your friend here.

    Consider the number 27.

    If 7 has 5 results, and 20 has 732 results, then you know that 27 has at least (732 * 5) results. You can use a two variable system (1 + 26, 2 + 25 ... etc) using the precomputed values for those as you go. You don't have to recompute 25 or 26 because you already did them.

提交回复
热议问题