Project Euler Lab - Problem 186

#186 - Connectedness of a Network

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

Here are the records from a busy telephone system with one million users:

RecNrCallerCalled
\(1\)\(200007\)\(100053\)
\(2\)\(600183\)\(500439\)
\(3\)\(600863\)\(701497\)
\(\cdots\)\(\cdots\)\(\cdots\)

The telephone number of the caller and the called number in record \(n\) are \(\operatorname{Caller}(n) = S_{2n-1}\) and \(\operatorname{Called}(n) = S_{2n}\) where \(S_{1,2,3,\dots}\) come from the "Lagged Fibonacci Generator":

For \(1 \le k \le 55\), \(S_k = [100003 - 200003k + 300007k^3] \pmod{1000000}\).
For \(56 \le k\), \(S_k = [S_{k-24} + S_{k-55}] \pmod{1000000}\).

If \(\operatorname{Caller}(n) = \operatorname{Called}(n)\) then the user is assumed to have misdialled and the call fails; otherwise the call is successful.

From the start of the records, we say that any pair of users \(X\) and \(Y\) are friends if \(X\) calls \(Y\) or vice-versa. Similarly, \(X\) is a friend of a friend of \(Z\) if \(X\) is a friend of \(Y\) and \(Y\) is a friend of \(Z\); and so on for longer chains.

The Prime Minister's phone number is \(524287\). After how many successful calls, not counting misdials, will \(99\%\) of the users (including the PM) be a friend, or a friend of a friend etc., of the Prime Minister?

This problem is taken from Project Euler, Problem 186.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=186. Published Saturday, 15th March 2008, 05:00 am. Solved by 3,379 members at time of mirroring.

Why this is useful

Numerical Computing. Matrix methods and linear-recurrence acceleration are the machinery behind covariance work, PCA, and lattice/transition models (Phases 4, 5, 8).

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.