Project Euler Lab - Problem 285

#285 - Pythagorean Odds

● AdvancedOfficial difficulty: 46%PointsTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

Albert chooses a positive integer \(k\), then two real numbers \(a, b\) are randomly chosen in the interval \([0,1]\) with uniform distribution.
The square root of the sum \((k \cdot a + 1)^2 + (k \cdot b + 1)^2\) is then computed and rounded to the nearest integer. If the result is equal to \(k\), he scores \(k\) points; otherwise he scores nothing.

For example, if \(k = 6\), \(a = 0.2\) and \(b = 0.85\), then \((k \cdot a + 1)^2 + (k \cdot b + 1)^2 = 42.05\).
The square root of \(42.05\) is \(6.484\cdots\) and when rounded to the nearest integer, it becomes \(6\).
This is equal to \(k\), so he scores \(6\) points.

It can be shown that if he plays \(10\) turns with \(k = 1, k = 2, \dots, k = 10\), the expected value of his total score, rounded to five decimal places, is \(10.20914\).

If he plays \(10^5\) turns with \(k = 1, k = 2, k = 3, \dots, k = 10^5\), what is the expected value of his total score, rounded to five decimal places?

This problem is taken from Project Euler, Problem 285.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=285. Published Saturday, 3rd April 2010, 05:00 am. Solved by 1,457 members at time of mirroring.

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.