Project Euler Lab - Problem 569

#569 - Prime Mountain Range

● AdvancedOfficial difficulty: 44%Two-player gamesTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

A mountain range consists of a line of mountains with slopes of exactly \(45^\circ\), and heights governed by the prime numbers, \(p_n\). The up-slope of the \(k\)th mountain is of height \(p_{2k - 1}\), and the downslope is \(p_{2k}\). The first few foot-hills of this range are illustrated below.

0569-prime-mountain-range.gif

Tenzing sets out to climb each one in turn, starting from the lowest. At the top of each peak, he looks back and counts how many of the previous peaks he can see. In the example above, the eye-line from the third mountain is drawn in red, showing that he can only see the peak of the second mountain from this viewpoint. Similarly, from the \(9\)th mountain, he can see three peaks, those of the \(5\)th, \(7\)th and \(8\)th mountain.

Let \(P(k)\) be the number of peaks that are visible looking back from the \(k\)th mountain. Hence \(P(3)=1\) and \(P(9)=3\).
Also \(\displaystyle \sum_{k=1}^{100} P(k) = 227\).

Find \(\displaystyle \sum_{k=1}^{2500000} P(k)\).

This problem is taken from Project Euler, Problem 569.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=569. Published Saturday, 10th September 2016, 07:00 pm. Solved by 474 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 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.