Saving Paper
When wrapping n unit cubes individually, each cube requires 6 square units of paper (surface area of a unit cube). Alternatively, one can arrange the cubes into a rectangular box of dimensions a x...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
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) = \displaystyle \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$.
Problem 775: Saving Paper
Mathematical Foundation
Lemma 1 (Box Surface Area). For positive integers , the surface area of an box is . For fixed volume , the surface area is minimized when are as close to as possible.
Proof. By the AM-GM inequality, for fixed , , with equality when . Since must be integers and we only require (not ), the optimal box may have volume strictly greater than .
Definition. For a triple with , define .
Theorem 1 (Reformulation of ). We have
Thus the problem reduces to computing .
Proof. Direct algebraic manipulation.
Lemma 2 (Counting by Box). For each triple with , the box is optimal for a contiguous range of values. Specifically, box is optimal for in some interval . Thus
Proof. As increases, the optimal box dimensions grow. For a given , it is optimal for values where (i) , (ii) no smaller box covers , and (iii) using a larger box is more expensive. The transitions occur at values of that are products for nearby triples.
Theorem 2 (Summation via Dimension Enumeration). The sum can be computed by iterating over the first dimension from to , and for each , iterating over from to , and for each , determining the optimal range of covered. This yields:
where the summation over accounts for the number of -values for which is the optimal wrapping.
Proof. We enumerate boxes in order of increasing surface area for each -pair. For fixed , increasing increases both volume and surface area. The box covers -values from the previous box’s volume to . The surface area contribution is times the count of -values in this range. The outer loop over runs up to and the middle loop over runs up to , giving an overall iteration count of .
Lemma 3 (Optimal Box Characterization). For a given , the optimal box satisfies , , and . Moreover, one need not always have ; sometimes gives smaller surface area.
Proof. If , then , meaning or , contradicting . Similarly, would force . For the last claim, consider : the box has surface area , while has surface area . Indeed may exceed , making .
Editorial
Wrap unit cubes together vs separately. = max paper savings. . Given . Find . We iterate over c from b to …, box (a,b,c) covers n in (prev_vol, abc]. We then we need to compute contribution of all valid c values. Finally, actually: iterate c from b upward.
Pseudocode
For each a from 1 to N^{1/3}
For each b from a to floor((N/a)^{1/2})
For c from b to ..., box (a,b,c) covers n in (prev_vol, a*b*c]
We need to compute contribution of all valid c values
Actually: iterate c from b upward
The range of n for box (a,b,c) is (a*b*(c-1), a*b*c] intersected with [1, N]
Handle overcounting: a box (a,b,c) might not be optimal for all n in its range
Need to take minimum over all boxes -- this naive approach overcounts
Correct approach: for each n, S(n) = min over (a,b,c) with abc >= n
The enumeration must ensure we pick the minimum surface area box
Refined approach: for each (a, b), compute S(a,b) = 2(ab + b*ceil(n/ab) + a*ceil(n/ab))
and track the running minimum
More refined: use the "hyperbola method" style enumeration
Enumerate all (a, b) pairs, for each compute the c = ceil(n/(ab)) contribution
Sum over n by grouping n-values with same ceil(n/(ab))
Complexity Analysis
- Time: — the double loop over and contributes iterations. For , this is approximately , which requires further optimization (e.g., grouping consecutive -values with the same ceiling, reducing to or better).
- Space: auxiliary space (all computations are streaming).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 775: Saving Paper
*
* Wrap $n$ unit cubes together vs separately. $g(n)$ = max paper savings. $G(N)=\sum g(n)$. Given $G(18)=530, G(10^6)\equiv 951640919 \pmod{10^9+7}$. Fi
*/
int main() { printf("Problem 775: Saving Paper\n"); return 0; }
"""
Problem 775: Saving Paper
Wrap $n$ unit cubes together vs separately. $g(n)$ = max paper savings. $G(N)=\sum g(n)$. Given $G(18)=530, G(10^6)\equiv 951640919 \pmod{10^9+7}$. Find $G(10^{{16}}) \bmod 10^9+7$.
"""
print("Problem 775: Saving Paper")