Project Euler Lab - Problem 247

#247 - Squares Under a Hyperbola

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

Consider the region constrained by \(1 \le x\) and \(0 \le y \le 1/x\).

Let \(S_1\) be the largest square that can fit under the curve.
Let \(S_2\) be the largest square that fits in the remaining area, and so on.
Let the index of \(S_n\) be the pair \((\text{left}, \text{below})\) indicating the number of squares to the left of \(S_n\) and the number of squares below \(S_n\).

The diagram shows some such squares labelled by number.
\(S_2\) has one square to its left and none below, so the index of \(S_2\) is \((1,0)\).
It can be seen that the index of \(S_{32}\) is \((1,1)\) as is the index of \(S_{50}\).
\(50\) is the largest \(n\) for which the index of \(S_n\) is \((1,1)\).

What is the largest \(n\) for which the index of \(S_n\) is \((3,3)\)?

This problem is taken from Project Euler, Problem 247.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=247. Published Friday, 29th May 2009, 09:00 pm. Solved by 1,739 members at time of mirroring.

Why this is useful

General Problem Solving. Builds computational thinking, decomposition, and debugging discipline - transferable, without a specific financial application.

We classify relevance honestly - not every Euler problem is a trading application.

Prerequisites

Lessons that prepare you:
19.10 Search: Backtracking, Branch-and-Bound, Binary Search, Meet-in-the-Middle · 3.1 Vectors, Multivariable Functions, and Level Sets

Recommended stepping-stone problems: #139 · #148 · #142

Concepts: geometry

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.