PyPE solution to PE problem 76

Registered by Scott Armitage

PyPE solution to PE problem 76

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Scott Armitage
Completed by
Scott Armitage

Related branches

Sprints

Whiteboard

    ProjectEuler.net problem 76
    ===========================

    It is possible to write five as a sum in exactly six different ways:

        4 + 1
        3 + 2
        3 + 1 + 1
        2 + 2 + 1
        2 + 1 + 1 + 1
        1 + 1 + 1 + 1 + 1

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

    Solution
    --------

    What we are looking for is the number of partitions of an integer n, denoted
    by p(n). Note that since we are looking for at least 2 integers in the sum,
    we really want sum(p(n,k)) for k in 2..n, however p(n,1) = 1, so we simply
    subtract 1 from p(n) to obtain our desired solution.

    We can use Euler's generating function (from Wikipedia):

        (1 + x + x**2 + ...) * ( 1 + x**2 + ... ) * ( 1 + x**3 + ... ) * ...

    where the coefficient of the x**n term counts the number of partitions of n.

    So, we simply need to perform a polynomial expansion of the bove, but we
    note that we only care about terms up to x**n; anything above that is
    superfluous.

    Answer
    ------

    190569291

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.