Project Euler Lab - Problem 278

#278 - Linear Combinations of Semiprimes

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

Given the values of integers \(1 < a_1 < a_2 < \dots < a_n\), consider the linear combination
\(q_1 a_1+q_2 a_2 + \dots + q_n a_n=b\), using only integer values \(q_k \ge 0\).

Note that for a given set of \(a_k\), it may be that not all values of \(b\) are possible.
For instance, if \(a_1=5\) and \(a_2=7\), there are no \(q_1 \ge 0\) and \(q_2 \ge 0\) such that \(b\) could be
\(1, 2, 3, 4, 6, 8, 9, 11, 13, 16, 18\) or \(23\).
In fact, \(23\) is the largest impossible value of \(b\) for \(a_1=5\) and \(a_2=7\).
We therefore call \(f(5, 7) = 23\).
Similarly, it can be shown that \(f(6, 10, 15)=29\) and \(f(14, 22, 77) = 195\).

Find \(\displaystyle \sum f( p\, q,p \, r, q \, r)\), where \(p\), \(q\) and \(r\) are prime numbers and \(p < q < r < 5000\).

This problem is taken from Project Euler, Problem 278.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=278. Published Saturday, 13th February 2010, 05:00 am. Solved by 1,260 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.