Project Euler Lab - Problem 201

#201 - Subsets with a Unique Sum

● AdvancedOfficial difficulty: 34%CountingTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

For any set \(A\) of numbers, let \(\operatorname{sum}(A)\) be the sum of the elements of \(A\).
Consider the set \(B = \{1,3,6,8,10,11\}\).
There are \(20\) subsets of \(B\) containing three elements, and their sums are:

\[\begin{align} \operatorname{sum}(\{1,3,6\}) &= 10,\\ \operatorname{sum}(\{1,3,8\}) &= 12,\\ \operatorname{sum}(\{1,3,10\}) &= 14,\\ \operatorname{sum}(\{1,3,11\}) &= 15,\\ \operatorname{sum}(\{1,6,8\}) &= 15,\\ \operatorname{sum}(\{1,6,10\}) &= 17,\\ \operatorname{sum}(\{1,6,11\}) &= 18,\\ \operatorname{sum}(\{1,8,10\}) &= 19,\\ \operatorname{sum}(\{1,8,11\}) &= 20,\\ \operatorname{sum}(\{1,10,11\}) &= 22,\\ \operatorname{sum}(\{3,6,8\}) &= 17,\\ \operatorname{sum}(\{3,6,10\}) &= 19,\\ \operatorname{sum}(\{3,6,11\}) &= 20,\\ \operatorname{sum}(\{3,8,10\}) &= 21,\\ \operatorname{sum}(\{3,8,11\}) &= 22,\\ \operatorname{sum}(\{3,10,11\}) &= 24,\\ \operatorname{sum}(\{6,8,10\}) &= 24,\\ \operatorname{sum}(\{6,8,11\}) &= 25,\\ \operatorname{sum}(\{6,10,11\}) &= 27,\\ \operatorname{sum}(\{8,10,11\}) &= 29. \end{align}\]

Some of these sums occur more than once, others are unique.
For a set \(A\), let \(U(A,k)\) be the set of unique sums of \(k\)-element subsets of \(A\), in our example we find \(U(B,3) = \{10,12,14,18,21,25,27,29\}\) and \(\operatorname{sum}(U(B,3)) = 156\).

Now consider the \(100\)-element set \(S = \{1^2, 2^2, \dots, 100^2\}\).
S has \(100891344545564193334812497256\) \(50\)-element subsets.

Determine the sum of all integers which are the sum of exactly one of the \(50\)-element subsets of \(S\), i.e. find \(\operatorname{sum}(U(S,50))\).

This problem is taken from Project Euler, Problem 201.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=201. Published Saturday, 5th July 2008, 02:00 pm. Solved by 2,790 members at time of mirroring.

Why this is useful

Algorithmic Development. Optimal substructure and state-space reasoning are exactly how American-option pricing and optimal execution are solved (Phases 13, 16).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.