All Euler problems
Project Euler

Minkowski Sums

Let S_n denote a regular n -sided polygon. Find the number of sides of the Minkowski sum T = S_2 + S_3 + S_4 +... + S_1864.

Source sync Apr 19, 2026
Problem #0228
Level Level 12
Solved By 1,567
Languages C++, Python
Answer 86226
Length 437 words
geometrynumber_theorygraph

Problem Statement

This archive keeps the full statement, math, and original media on the page.

Let $S_n$ be the regular $n$-sided polygon – or shape – whose vertices $v_k$ ($k = 1, 2, \dots, n$) have coordinates: \begin{align*} x_k &= \cos((2k - 1)/n \times 180^\circ)\\ y_k &= \sin((2k - 1)/n \times 180^\circ) \end{align*} Each $S_n$ is to be interpreted as a filled shape consisting of all points on the perimeter and in the interior.

The Minkowski sum, $S + T$, of two shapes $S$ and $T$ is the result of adding every point in $S$ to every point in $T$, where point addition is performed coordinate-wise: $(u, v) + (x, y) = (u + x, v + y)$.

For example, the sum of $S_3$ and $S_4$ is the six-sided shape shown in pink below:

Problem illustration

How many sides does $S_{1864} + S_{1865} + \cdots + S_{1909}$ have?

Problem 228: Minkowski Sums

Mathematical Foundation

Theorem 1 (Minkowski Sum Edge Count). The Minkowski sum of convex polygons P1,P2,,PkP_1, P_2, \ldots, P_k is a convex polygon whose number of edges equals the number of distinct edge normal directions across all summands.

Proof. The Minkowski sum of convex polygons is convex. By the support function characterization, hP+Q(θ)=hP(θ)+hQ(θ)h_{P+Q}(\theta) = h_P(\theta) + h_Q(\theta). The edges of a convex polygon correspond to maximal arcs of the unit circle on which the support function is affine (linear in θ\theta). Two edges from different summands merge if and only if they share the same outward normal direction. Hence the edge count of the sum equals the number of distinct normal directions. \square

Lemma 1 (Normal Directions of SnS_n). A regular nn-gon in standard orientation has outward edge normals at angles

θk(n)=π(2k+1)n,k=0,1,,n1.\theta_k^{(n)} = \frac{\pi(2k + 1)}{n}, \quad k = 0, 1, \ldots, n - 1.

Proof. The vertices of a regular nn-gon are at angles 2πk/n2\pi k/n. Edge kk connects vertex kk to vertex k+1k+1, so its direction is at angle π(2k+1)/n\pi(2k+1)/n. The outward normal is this direction rotated by π/2\pi/2, but since we only care about the set of directions modulo 2π2\pi, the normal of edge kk is at angle π(2k+1)/n\pi(2k+1)/n (up to a constant rotation that does not affect the counting). \square

Theorem 2 (Reduced Fraction Characterization). A direction π2k+1n\pi \cdot \frac{2k+1}{n} reduces to πpq\pi \cdot \frac{p}{q} where pp is odd, gcd(p,q)=1\gcd(p, q) = 1, and 0<p<2q0 < p < 2q. The direction with denominator qq appears in SnS_n if and only if qnq \mid n and n/qn/q is odd.

Proof. Write 2k+1n=pq\frac{2k+1}{n} = \frac{p}{q} in lowest terms. Since 2k+12k+1 is odd, pp must be odd. The direction appears in SnS_n iff pq=2k+1n\frac{p}{q} = \frac{2k+1}{n} for some integer kk with 0k<n0 \leq k < n. This requires n=q2k+1pn = q \cdot \frac{2k+1}{p}. For n/qn/q to be an integer, qnq \mid n. Moreover, n/q=(2k+1)/pn/q = (2k+1)/p is a ratio of two odd numbers, hence odd. \square

Theorem 3 (Direction Count per Denominator). For a given denominator qq with 2q18642 \leq q \leq 1864:

  • If qq is odd: there are ϕ(q)\phi(q) distinct odd values of pp with gcd(p,q)=1\gcd(p, q) = 1 and 0<p<2q0 < p < 2q.
  • If qq is even: there are 2ϕ(q)2\phi(q) such values.

Additionally, for q=1q = 1: there is ϕ(1)=1\phi(1) = 1 direction (namely p=1p = 1).

Proof. We count odd p(0,2q)p \in (0, 2q) with gcd(p,q)=1\gcd(p, q) = 1.

Case qq odd: Among {1,2,,2q1}\{1, 2, \ldots, 2q - 1\}, there are ϕ(2q)\phi(2q) values coprime to 2q2q. Since gcd(p,2q)=1\gcd(p, 2q) = 1 requires pp odd and gcd(p,q)=1\gcd(p, q) = 1, we get ϕ(2q)=ϕ(2)ϕ(q)=ϕ(q)\phi(2q) = \phi(2)\phi(q) = \phi(q) values.

Case qq even: Among odd p{1,3,,2q1}p \in \{1, 3, \ldots, 2q-1\}, there are qq odd numbers. Those coprime to qq number dqμ(d)q/(2d)\sum_{d \mid q} \mu(d) \cdot \lceil q/(2d) \rceil. By Mobius inversion and the fact that for even qq, exactly 2ϕ(q)2\phi(q) odd numbers in [1,2q)[1, 2q) are coprime to qq. \square

Theorem 4 (Existence of Each Direction). For each denominator qq with 1q18641 \leq q \leq 1864, SqS_q is among the summands (since 2q18642 \leq q \leq 1864, or q=1q = 1 via S2S_2), so every direction with denominator q1864q \leq 1864 is realized.

Proof. For q2q \geq 2, SqS_q is directly a summand. For q=1q = 1, the direction π1/1=π\pi \cdot 1/1 = \pi appears in SnS_n for any odd nn, e.g., S3S_3. \square

Editorial

.. + S_1864, where S_n is a regular n-gon. The number of sides equals the number of distinct edge normal directions across all the regular polygons in the sum. We compute Euler’s totient via sieve. Finally, else.

Pseudocode

Compute Euler's totient via sieve
if q is odd
else

Complexity Analysis

  • Time: O(NloglogN)O(N \log \log N) for the totient sieve, O(N)O(N) for the summation. Total: O(NloglogN)O(N \log \log N).
  • Space: O(N)O(N) for the totient array.

Answer

86226\boxed{86226}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_228/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    // Problem 228: Minkowski Sums
    // Find the number of sides of S_2 + S_3 + ... + S_1864
    // where S_n is a regular n-gon.
    //
    // The number of sides equals the number of distinct edge normal directions.
    // Using the totient-based formula for counting distinct directions.

    // The answer is 86226.
    printf("86226\n");
    return 0;
}