Project Euler Lab - Problem 333

#333 - Special Partitions

● AppliedOfficial difficulty: 22%CountingTier B - browser, with the efficient algorithmNot viewed
↖ Euler Lab

All positive integers can be partitioned in such a way that each and every term of the partition can be expressed as \(2^i \times 3^j\), where \(i,j \ge 0\).

Let's consider only such partitions where none of the terms can divide any of the other terms.
For example, the partition of \(17 = 2 + 6 + 9 = (2^1 \times 3^0 + 2^1 \times 3^1 + 2^0 \times 3^2)\) would not be valid since \(2\) can divide \(6\). Neither would the partition \(17 = 16 + 1 = (2^4 \times 3^0 + 2^0 \times 3^0)\) since \(1\) can divide \(16\). The only valid partition of \(17\) would be \(8 + 9 = (2^3 \times 3^0 + 2^0 \times 3^2)\).

Many integers have more than one valid partition, the first being \(11\) having the following two partitions.
\(11 = 2 + 9 = (2^1 \times 3^0 + 2^0 \times 3^2)\)
\(11 = 8 + 3 = (2^3 \times 3^0 + 2^0 \times 3^1)\)

Let's define \(P(n)\) as the number of valid partitions of \(n\). For example, \(P(11) = 2\).

Let's consider only the prime integers \(q\) which would have a single valid partition such as \(P(17)\).

The sum of the primes \(q \lt 100\) such that \(P(q)=1\) equals \(233\).

Find the sum of the primes \(q \lt 1000000\) such that \(P(q)=1\).

This problem is taken from Project Euler, Problem 333.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=333. Published Saturday, 16th April 2011, 01:00 pm. Solved by 1,479 members at time of mirroring.

Why this is useful

Mathematical Foundation. Exact counting underlies discrete pricing lattices, scenario enumeration, and combinatorial probability (Phase 7).

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 B - browser, with the efficient algorithm
Runs in the browser only with the intended efficient algorithm; a naive loop will hit the timeout.

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.