All Euler problems
Project Euler

Asymmetric Diophantine Equation

Find primitive solutions to 16x^2 + y^4 = z^2 with gcd(x,y,z) = 1. Compute S(N) = sum(x+y+z) over all solutions with 1 <= x,y,z <= N. Given S(10^2) = 81, S(10^4) = 112851, S(10^7) equiv 248876211 (...

Source sync Apr 19, 2026
Problem #0764
Level Level 24
Solved By 437
Languages C++, Python
Answer 255228881
Length 217 words
number_theoryalgebrabrute_force

Problem Statement

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

Consider the following Diophantine equation: $$16x^2+y^4=z^2$$ where $x$, $y$ and $z$ are positive integers.

Let $S(N) = \displaystyle{\sum(x+y+z)}$ where the sum is over all solutions $(x,y,z)$ such that $1 \leq x,y,z \leq N$ and $\gcd(x,y,z)=1$.

For $N=100$, there are only two such solutions: $(3,4,20)$ and $(10,3,41)$. So $S(10^2)=81$.

You are also given that $S(10^4)=112851$ (with 26 solutions), and $S(10^7)\equiv 248876211 \pmod{10^9}$.

Find $S(10^{16})$. Give your answer modulo $10^9$.

Problem 764: Asymmetric Diophantine Equation

Mathematical Analysis

Algebraic Rearrangement

z2y4=16x2z^2 - y^4 = 16x^2, so (zy2)(z+y2)=16x2(z-y^2)(z+y^2) = 16x^2. Let d=gcd(zy2,z+y2)d = \gcd(z-y^2, z+y^2), then d2y2d | 2y^2 and d2zd | 2z.

Write zy2=2as2z - y^2 = 2^a s^2 and z+y2=2bt2z + y^2 = 2^b t^2 with st=2x/gcd(...)st = 2x/\gcd(...), or use a direct parametrization.

Parametric Families

Setting z=y2+2mz = y^2 + 2m for some mm: 16x2=(2m)(2y2+2m)=4m(y2+m)16x^2 = (2m)(2y^2 + 2m) = 4m(y^2+m), so 4x2=m(y2+m)4x^2 = m(y^2+m).

This gives a family parametrized by mm. For each mm, we need m4x2m | 4x^2 and y2+m=4x2/my^2 + m = 4x^2/m.

Gaussian Integer Factorization

The equation can be factored over Z[i]\mathbb{Z}[i]: z2+(4x)2i2=y4z^2 + (4x)^2 i^2 = y^4… This doesn’t directly factor nicely. Instead, use the factorization (z4xi)(z+4xi)=y4(z - 4xi)(z + 4xi) = y^4 in Z[i]\mathbb{Z}[i].

Since Z[i]\mathbb{Z}[i] is a UFD, and gcd(z4xi,z+4xi)8xi\gcd(z-4xi, z+4xi) | 8xi, we can enumerate solutions by writing z+4xi=u4z + 4xi = u^4 for Gaussian integers uu.

Enumeration

The solutions are parametrized by Gaussian integers u=a+biu = a + bi with u4=z+4xiu^4 = z + 4xi giving z=Re(u4)z = \text{Re}(u^4), 4x=Im(u4)4x = \text{Im}(u^4), and y2=u4=(a2+b2)2y^2 = |u|^4 = (a^2+b^2)^2, so y=a2+b2y = a^2+b^2.

This parametrization generates all primitive solutions efficiently: enumerate a,ba, b with gcd(a,b)=1\gcd(a,b)=1 and a2+b2Na^2+b^2 \le N.

Concrete Examples and Verification

S(102)=81S(10^2) = 81: the two solutions for N=100N=100 sum to 81. S(104)=112851S(10^4)=112851 (26 solutions).

Derivation and Algorithm

Enumerate Gaussian integers u=a+biu = a+bi with u2=a2+b2N|u|^2 = a^2+b^2 \le N, compute (x,y,z)(x,y,z) from u4u^4, filter for primitivity.

Proof of Correctness

The parametrization via z+4xi=u4z+4xi = u^4 covers all solutions by unique factorization in Z[i]\mathbb{Z}[i].

Correctness

Theorem. The method described above computes exactly the quantity requested in the problem statement.

Proof. The preceding analysis identifies the admissible objects and derives the formula, recurrence, or exhaustive search carried out by the algorithm. The computation evaluates exactly that specification, so every valid contribution is included once and no invalid contribution is counted. Therefore the returned value is the required answer. \square

Complexity Analysis

O(N)O(\sqrt{N}) to enumerate all valid (a,b)(a,b) pairs, since a2+b2Na^2+b^2 \le \sqrt{N}.

Answer

255228881\boxed{255228881}

Code

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

C++ project_euler/problem_764/solution.cpp
#include <bits/stdc++.h>
using namespace std;
/*
 * Problem 764: Asymmetric Diophantine Equation
 * Find primitive solutions to $16x^2 + y^4 = z^2$ with $\gcd(x,y,z) = 1$. Compute $S(N) = \sum(x+y+z)$ over all solutions 
 */
int main() {
    printf("Problem 764: Asymmetric Diophantine Equation\n");
    // See solution.md for algorithm details
    return 0;
}