Integer Points on Ellipses
Find the number of integer solutions (x, y) to 3x^2 + 5y^2 <= 10^6.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Given a prime \(p\) and a positive integer \(n < p\), let \(R(p, n)\) be the
In other words, \(R(p, n)\) is the minimal positive integer \(r\) such that \[p^r \equiv 1 \pmod {n!}\] For example, \(R(7, 4) = 2\) and \(R(10^9 + 7, 12) = 17280\).
For example, \(R(7, 4) = 2\) and \(R(10^9 + 7, 12) = 17280\).
For example, \(R(7, 4) = 2\) and \(R(10^9 + 7, 12) = 17280\).
Problem 952: Integer Points on Ellipses
Mathematical Foundation
Theorem 1 (Generalized Gauss Circle Problem). The number of lattice points inside the ellipse satisfies
for any .
Proof. The leading term equals the area of the ellipse , which has semi-axes and , giving area . Each lattice point can be associated with the unit square . The discrepancy between and the area arises from unit squares that straddle the ellipse boundary. The boundary has arc length , and each boundary-straddling square contributes error, so the total error is . Sharper bounds (e.g., via Huxley’s method) require deeper analytic techniques.
Lemma 1 (Slice Counting). For fixed with , the number of integers satisfying is
Proof. The constraint yields . The integer solutions are where . This set has cardinality .
Theorem 2 (Exact Count via Slicing). The total lattice point count is
Proof. For each integer with , we have , so the slice is non-empty. Lemma 1 gives the count for each slice. Summing over all valid counts every lattice point with exactly once, since the slices partition the lattice points by their -coordinate.
Lemma 2 (Symmetry Reduction). By the symmetry :
where is the -range at .
Proof. The slice contributes points. For , the slices at and have identical -ranges (since ), so each pair contributes twice the count of a single slice.
Editorial
Count integer (x, y) with 3x^2 + 5y^2 <= N, where N = 10^6. The lattice point count for ellipse Ax^2 + By^2 <= N is approximately pi*N/sqrt(AB), with error O(sqrt(N)). We compute exactly by slicing: for each valid x, count y-values satisfying y^2 <= (N - 3x^2) / 5. Complexity: O(sqrt(N)) time, O(1) space.
Pseudocode
x_max = floor(sqrt(N / 3))
count = 0
For x from -x_max to x_max:
R = N - 3 * x * x
y_max = floor(sqrt(R / 5))
count = count + 2 * y_max + 1
Return count
Complexity Analysis
- Time: iterations of the outer loop, each performing work (one integer square root computation).
- Space: beyond the loop variable and accumulator.
For : approximately iterations.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
/*
* Problem 952: Integer Points on Ellipses
*
* Count integer (x, y) with 3x^2 + 5y^2 <= N, N = 10^6.
*
* For each x in [-sqrt(N/3), sqrt(N/3)], count y in [-M, M] where
* M = floor(sqrt((N - 3x^2) / 5)).
*
* Complexity: O(sqrt(N)) time, O(1) space.
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
const long long N = 1000000;
long long count = 0;
int max_x = (int)sqrt((double)N / 3.0);
// Adjust for floating-point imprecision
while (3LL * (max_x + 1) * (max_x + 1) <= N) max_x++;
while (3LL * max_x * max_x > N) max_x--;
for (int x = -max_x; x <= max_x; x++) {
long long rem = N - 3LL * x * x;
if (rem < 0) continue;
int max_y = (int)sqrt((double)rem / 5.0);
// Correct floating-point floor
while (5LL * (max_y + 1) * (max_y + 1) <= rem) max_y++;
while (5LL * max_y * max_y > rem) max_y--;
count += 2 * max_y + 1;
}
cout << count << endl;
return 0;
}
"""
Problem 952: Integer Points on Ellipses
Count integer (x, y) with 3x^2 + 5y^2 <= N, where N = 10^6.
The lattice point count for ellipse Ax^2 + By^2 <= N is approximately
pi*N/sqrt(AB), with error O(sqrt(N)). We compute exactly by slicing:
for each valid x, count y-values satisfying y^2 <= (N - 3x^2) / 5.
Complexity: O(sqrt(N)) time, O(1) space.
"""
import numpy as np
from math import isqrt
def solve(N: int = 10**6) -> int:
"""Count integer points (x, y) with 3x^2 + 5y^2 <= N."""
count = 0
max_x = isqrt(N // 3)
for x in range(-max_x, max_x + 1):
rem = N - 3 * x * x
if rem < 0:
continue
max_y = isqrt(rem // 5)
# Verify floor correctness
while 5 * max_y * max_y > rem:
max_y -= 1
count += 2 * max_y + 1
return count
# --- Compute answer ---
N = 10**6
answer = solve(N)
area_approx = np.pi * N / np.sqrt(15)
print(f"Exact count: {answer}")
print(f"Area estimate: {area_approx:.1f}")
print(f"Relative error: {abs(answer - area_approx) / area_approx:.4%}")
print(answer)