All Euler problems
Project Euler

Minimum Area Ellipse

A symmetrical convex grid polygon is a convex polygon whose vertices all have integer coordinates, all internal angles are strictly less than 180°, and it has both horizontal and vertical symmetry....

Source sync Apr 19, 2026
Problem #0742
Level Level 36
Solved By 193
Languages C++, Python
Answer 18397727
Length 511 words
geometryoptimizationlinear_algebra

Problem Statement

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

A symmetrical convex grid polygon is polygon such that:

  • All its vertices have integer coordinates.

  • All its internal angles are strictly smaller than $180^\circ$.

  • It has both horizontal and vertical symmetry.

For example, the left polygon is a convex grid polygon which has neither horizontal nor vertical symmetry, while the right one is a valid symmetrical convex grid polygon with six vertices:

Problem illustration

Define $A(N)$, the minimum area of a symmetrical convex grid polygon with $N$ vertices.

You are given $A(4) = 1$, $A(8) = 7$, $A(40) = 1039$ and $A(100) = 17473$.

Find $A(1000)$.

Problem 742: Minimum Area Ellipse

Mathematical Foundation

Theorem 1 (Convex Lattice Polygon Edge-Vector Characterization). A convex lattice polygon is uniquely determined (up to translation) by its sequence of edge vectors (v1,v2,,vN)(v_1, v_2, \ldots, v_N), where each viZ2v_i \in \mathbb{Z}^2 is primitive (i.e., gcd(vi,x,vi,y)=1\gcd(|v_{i,x}|, |v_{i,y}|) = 1 or the vector is a unit coordinate vector), the vectors are sorted by angle, ivi=0\sum_i v_i = \mathbf{0}, and consecutive vectors turn strictly left (positive cross product).

Proof. This is the standard characterization of convex lattice polygons. The edge vectors of a convex polygon, traversed counterclockwise, form a sequence with strictly increasing argument in [0,2π)[0, 2\pi). Primitivity ensures exactly one lattice point per edge (the vertices). The zero-sum condition ensures closure. Strict left turns ensure strict convexity (all internal angles <180°< 180°). \square

Theorem 2 (Double Symmetry Constraint). A convex lattice polygon with both horizontal and vertical axes of symmetry has its edge vectors partitioned into four congruent groups related by 90°90° rotations (or 180°180° reflections). Vertices come in orbits of size 44 (generic), 22 (on an axis), or 11 (at the origin, impossible for a vertex of a convex polygon with both symmetries unless N4N \le 4).

Proof. Let the symmetry axes be the coordinate axes. If v=(a,b)v = (a, b) is an edge vector in the first-quadrant arc, then (b,a)(-b, a), (a,b)(-a, -b), and (b,a)(b, -a) must also appear (from the reflections and rotations). For vectors on the axes, the orbit has size 22. Therefore N0(mod4)N \equiv 0 \pmod{4} (or N0(mod2)N \equiv 0 \pmod{2} when axis-aligned vertices are present). \square

Lemma 1 (Minimum Area via Farey Vectors). The minimum-area convex lattice polygon with NN vertices and both symmetries is constructed by selecting the N/4N/4 primitive lattice vectors in the first-quadrant angular sector [0°,90°)[0°, 90°) with smallest Farey-sequence denominators (i.e., closest to the axes), then mirroring across both axes. The area is computed by the shoelace formula.

Proof. Among all convex lattice polygons with NN vertices and both symmetries, the one minimizing area must use edge vectors of minimal magnitude. Primitive lattice vectors sorted by angle in the first quadrant correspond to Stern-Brocot tree entries. Selecting the N/4N/4 “innermost” such vectors (those with smallest a+b|a| + |b| or equivalently those from the shallowest levels of the Stern-Brocot tree) and forming the convex hull yields the minimum area. The shoelace formula then gives:

A=12i(xiyi+1xi+1yi)A = \frac{1}{2} \left| \sum_{i} (x_i y_{i+1} - x_{i+1} y_i) \right|

applied to the resulting vertex sequence. \square

Lemma 2 (Area from Edge Vectors). Given edge vectors (v1,,vN)(v_1, \ldots, v_N) traversed counterclockwise, the area equals:

A=12i<jvi×vjA = \frac{1}{2} \sum_{i < j} |v_i \times v_j|

where vi×vj=vi,xvj,yvi,yvj,xv_i \times v_j = v_{i,x} v_{j,y} - v_{i,y} v_{j,x}.

Proof. By the shoelace formula, the area of a polygon with vertices P0,P1,,PN1P_0, P_1, \ldots, P_{N-1} is 12iPi×Pi+1\frac{1}{2}|\sum_i P_i \times P_{i+1}|. Expressing Pk=P0+j=0k1vjP_k = P_0 + \sum_{j=0}^{k-1} v_j and expanding yields the stated cross-product sum. \square

Editorial

A symmetrical convex grid polygon has integer-coordinate vertices, all internal angles strictly less than 180°180°, and both horizontal and vertical symmetry. Let A(N)A(N) be the minimum area of such. We generate primitive lattice vectors in first quadrant, sorted by angle. We then select N/4 vectors for the first quadrant. Finally, (adjusting for axis vectors which contribute to orbits of size 2).

Pseudocode

Generate primitive lattice vectors in first quadrant, sorted by angle
Select N/4 vectors for the first quadrant
(adjusting for axis vectors which contribute to orbits of size 2)
Mirror across both axes to get all N edge vectors
Compute vertices from edge vectors (cumulative sum)
Center the polygon
Compute area via shoelace formula

Complexity Analysis

  • Time: O(N2)O(N^2) for generating and sorting primitive vectors up to the required magnitude, plus O(N)O(N) for area computation. For N=1000N = 1000, this is feasible.
  • Space: O(N)O(N) for storing edge vectors and vertices.

Answer

18397727\boxed{18397727}

Code

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

C++ project_euler/problem_742/solution.cpp
#include <bits/stdc++.h>
using namespace std;
/*
 * Problem 742: Minimum Area Ellipse
 * A **symmetrical convex grid polygon** has integer-coordinate vertices, all internal angles strictly less than $180°$, an
 */
int main() {
    printf("Problem 742: Minimum Area Ellipse\n");
    // See solution.md for algorithm details
    return 0;
}