Project Euler Lab - Problem 775

#775 - Saving Paper

● ResearchOfficial difficulty: 64%CountingTier D - conceptual / notebook executionNot viewed
↖ Euler Lab

When wrapping several cubes in paper, it is more efficient to wrap them all together than to wrap each one individually. For example, with 10 cubes of unit edge length, it would take 30 units of paper to wrap them in the arrangement shown below, but 60 units to wrap them separately.

Define \(g(n)\) to be the maximum amount of paper that can be saved by wrapping \(n\) identical \(1\times 1\times 1\) cubes in a compact arrangement, compared with wrapping them individually. We insist that the wrapping paper is in contact with the cubes at all points, without leaving a void.

With \(10\) cubes, the arrangement illustrated above is optimal, so \(g(10)=60-30=30\). With \(18\) cubes, it can be shown that the optimal arrangement is as a \(3\times 3\times 2\), using \(42\) units of paper, whereas wrapping individually would use \(108\) units of paper; hence \(g(18) = 66\).

Define \[G(N) = \sum_{n=1}^N g(n).\] You are given that \(G(18) = 530\), and \(G(10^6) \equiv 951640919 \pmod {1\,000\,000\,007}\).

Find \(G(10^{16})\). Give your answer modulo \(1\,000\,000\,007\).

This problem is taken from Project Euler, Problem 775.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=775. Published Sunday, 5th December 2021, 01:00 am. Solved by 295 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 D - conceptual / notebook execution
Too heavy for browser Pyodide at original scale: the browser is used for planning, small cases and reasoning; full scale runs 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.