Project Euler Lab - Problem 579

#579 - Lattice Points in Lattice Cubes

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

A lattice cube is a cube in which all vertices have integer coordinates. Let \(C(n)\) be the number of different lattice cubes in which the coordinates of all vertices range between (and including) \(0\) and \(n\). Two cubes are hereby considered different if any of their vertices have different coordinates.
For example, \(C(1)=1\), \(C(2)=9\), \(C(4)=100\), \(C(5)=229\), \(C(10)=4469\) and \(C(50)=8154671\).

Different cubes may contain different numbers of lattice points.

For example, the cube with the vertices
\((0, 0, 0)\), \((3, 0, 0)\), \((0, 3, 0)\), \((0, 0, 3)\), \((0, 3, 3)\), \((3, 0, 3)\), \((3, 3, 0)\), \((3, 3, 3)\) contains \(64\) lattice points (\(56\) lattice points on the surface including the \(8\) vertices and \(8\) points within the cube).

In contrast, the cube with the vertices
\((0, 2, 2)\), \((1, 4, 4)\), \((2, 0, 3)\), \((2, 3, 0)\), \((3, 2, 5)\), \((3, 5, 2)\), \((4, 1, 1)\), \((5, 3, 3)\) contains only \(40\) lattice points (\(20\) points on the surface and \(20\) points within the cube), although both cubes have the same side length \(3\).

Let \(S(n)\) be the sum of the lattice points contained in the different lattice cubes in which the coordinates of all vertices range between (and including) \(0\) and \(n\).

For example, \(S(1)=8\), \(S(2)=91\), \(S(4)=1878\), \(S(5)=5832\), \(S(10)=387003\) and \(S(50)=29948928129\).

Find \(S(5000) \bmod 10^9\).

This problem is taken from Project Euler, Problem 579.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=579. Published Sunday, 27th November 2016, 01:00 am. Solved by 216 members at time of mirroring.

Why this is useful

Algorithmic Development. Graph/state-space search transfers to routing, dependency resolution, and execution-path optimisation (Phases 16, 17).

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.