(ProjectEuler) Sum Combinations

前端 未结 7 1633
忘了有多久
忘了有多久 2020-12-30 08:09

From ProjectEuler.net:

Prob 76: How many different ways can one hundred be written as a sum of at least two positive integers?

I have no ide

7条回答
  •  误落风尘
    2020-12-30 08:35

    Notice: My maths is a bit rusty but hopefully this will help...

    You are going well with your break down of the problem.

    Think Generally:

    • A number n can be written as (n-1)+1 or (n-2)+2
    • You generalise this to (n-m)+m
    • Remember that the above also applies to all numbers (including m)

    So the idea is to find the first set (lets say 5 = (5-1)+1) and then treat (5-1) as a new n...5 = 4 +1...5 = ((4-1)+1)+1. The once that is exhausted begin again on 5 = 3 + 2....which becomes 5 = ((3-1)+1)+2 ....= 2+1+2....breaking down each one as you go along.

提交回复
热议问题