Project Euler Lab - Problem 790

#790 - Clock Grid

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

There is a grid of length and width \(50515093\) points. A clock is placed on each grid point. The clocks are all analogue showing a single hour hand initially pointing at \(12\).

A sequence \(S_t\) is created where: \[ \begin{align} S_0 &= 290797\\ S_t &= S_{t-1}^2 \bmod 50515093 &t>0 \end{align} \] The four numbers \(N_t = (S_{4t-4}, S_{4t-3}, S_{4t-2}, S_{4t-1})\) represent a range within the grid, with the first pair of numbers representing the x-bounds and the second pair representing the y-bounds. For example, if \(N_t = (3,9,47,20)\), the range would be \(3\le x\le 9\) and \(20\le y\le47\), and would include \(196\) clocks.

For each \(t\) \((t>0)\), the clocks within the range represented by \(N_t\) are moved to the next hour \(12\rightarrow 1\rightarrow 2\rightarrow \cdots \).

We define \(C(t)\) to be the sum of the hours that the clock hands are pointing to after timestep \(t\).
You are given \(C(0) = 30621295449583788\), \(C(1) = 30613048345941659\), \(C(10) = 21808930308198471\) and \(C(100) = 16190667393984172\).

Find \(C(10^5)\).

This problem is taken from Project Euler, Problem 790.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=790. Published Saturday, 19th March 2022, 10:00 pm. Solved by 320 members at time of mirroring.

Why this is useful

Optimization. The transferable skill is replacing infeasible enumeration with a mathematical reduction - the core move in calibration and large-scale computation (Phases 10, 13).

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

Prerequisites

Lessons that prepare you:
19.14 Computational Complexity, Feasibility Estimation, and Proving Algorithms Correct · 19.6 Recurrence Relations and Generating Functions · 2.7 Sequences, Series, Convergence, and Power Series

Recommended stepping-stone problems: #208 · #343 · #219

Concepts: sequences-series brute-force-reduction

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.