Project Euler Lab - Problem 134

#134 - Prime Pair Connection

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

Consider the consecutive primes \(p_1 = 19\) and \(p_2 = 23\). It can be verified that \(1219\) is the smallest number such that the last digits are formed by \(p_1\) whilst also being divisible by \(p_2\).

In fact, with the exception of \(p_1 = 3\) and \(p_2 = 5\), for every pair of consecutive primes, \(p_2 \gt p_1\), there exist values of \(n\) for which the last digits are formed by \(p_1\) and \(n\) is divisible by \(p_2\). Let \(S\) be the smallest of these values of \(n\).

Find \(\sum S\) for every pair of consecutive primes with \(5 \le p_1 \le 1000000\).

This problem is taken from Project Euler, Problem 134.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=134. Published Friday, 15th December 2006, 06:00 pm. Solved by 8,193 members at time of mirroring.

Why this is useful

Mathematical Foundation. Exact integer reasoning and algorithmic efficiency. Foundational rigour and computational discipline rather than a direct trading application.

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.