<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Project_Euler%2F504</id>
	<title>Project Euler/504 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Project_Euler%2F504"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Project_Euler/504&amp;action=history"/>
	<updated>2026-06-19T12:20:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Project_Euler/504&amp;diff=30604&amp;oldid=prev</id>
		<title>Admin: Create page with problem statement, approach using Pick&#039;s theorem, and link to Java solution (via create-page on MediaWiki MCP Server)</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Project_Euler/504&amp;diff=30604&amp;oldid=prev"/>
		<updated>2026-06-16T23:33:20Z</updated>

		<summary type="html">&lt;p&gt;Create page with problem statement, approach using Pick&amp;#039;s theorem, and link to Java solution (via create-page on MediaWiki MCP Server)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
Let $ABCD$ be a quadrilateral whose vertices are lattice points lying on the coordinate axes as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
A(a, 0), \quad B(0, b), \quad C(-c, 0), \quad D(0, -d)&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where $1 \le a, b, c, d \le m$ and $a, b, c, d, m$ are integers.&lt;br /&gt;
&lt;br /&gt;
It can be shown that for $m = 4$ there are exactly $256$ valid ways to construct $ABCD$. Of these $256$ quadrilaterals, $42$ of them strictly contain a square number of lattice points.&lt;br /&gt;
&lt;br /&gt;
How many quadrilaterals $ABCD$ strictly contain a square number of lattice points for $m = 100$?&lt;br /&gt;
&lt;br /&gt;
==Approach==&lt;br /&gt;
&lt;br /&gt;
===Pick&amp;#039;s Theorem===&lt;br /&gt;
&lt;br /&gt;
The core of the solution is [[wikipedia:Pick&amp;#039;s theorem|Pick&amp;#039;s Theorem]], which relates the area of a simple lattice polygon to the number of interior and boundary lattice points:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
A = I + \frac{B}{2} - 1&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
* $A$ is the area of the polygon&lt;br /&gt;
* $I$ is the number of interior lattice points (those strictly inside the polygon)&lt;br /&gt;
* $B$ is the number of boundary lattice points (those on the edges or vertices)&lt;br /&gt;
&lt;br /&gt;
Rearranging to solve for interior points:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
I = A - \frac{B}{2} + 1&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Area Calculation===&lt;br /&gt;
&lt;br /&gt;
Using the [[wikipedia:Shoelace formula|shoelace formula]] with vertices in order $A \to B \to C \to D$:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
A = \frac{1}{2} \left| (a \cdot b + 0 \cdot 0 + (-c) \cdot (-d) + 0 \cdot 0) - (0 \cdot 0 + b \cdot (-c) + 0 \cdot 0 + (-d) \cdot a) \right|&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
A = \frac{1}{2} \left| ab + cd + bc + ad \right| = \frac{(a + c)(b + d)}{2}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Boundary Points===&lt;br /&gt;
&lt;br /&gt;
The number of lattice points on a line segment between two lattice points $(x_1, y_1)$ and $(x_2, y_2)$ is $\gcd(|x_2 - x_1|, |y_2 - y_1|) + 1$ (including both endpoints). For the four edges:&lt;br /&gt;
&lt;br /&gt;
* Edge $AB$: $\gcd(a, b) + 1$ points&lt;br /&gt;
* Edge $BC$: $\gcd(b, c) + 1$ points&lt;br /&gt;
* Edge $CD$: $\gcd(c, d) + 1$ points&lt;br /&gt;
* Edge $DA$: $\gcd(d, a) + 1$ points&lt;br /&gt;
&lt;br /&gt;
Summing these and subtracting the 4 vertices (counted twice) gives the total boundary count:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
B = \gcd(a, b) + \gcd(b, c) + \gcd(c, d) + \gcd(d, a)&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interior Points===&lt;br /&gt;
&lt;br /&gt;
Substituting into Pick&amp;#039;s Theorem:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
I = \frac{(a + c)(b + d)}{2} - \frac{\gcd(a, b) + \gcd(b, c) + \gcd(c, d) + \gcd(d, a)}{2} + 1&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since $(a + c)(b + d)$ is always even for this quadrilateral, integer division by 2 is exact.&lt;br /&gt;
&lt;br /&gt;
===Algorithm===&lt;br /&gt;
&lt;br /&gt;
Pre-compute a GCD table for all pairs of values from $1$ to $m$ using the Euclidean algorithm. Then iterate over all quadruples $(a, b, c, d)$ with $1 \le a, b, c, d \le m$:&lt;br /&gt;
&lt;br /&gt;
# Compute the area term: $\mathtt{area} = (a + c) \times (b + d)$&lt;br /&gt;
# Compute the boundary term by summing four GCD table lookups&lt;br /&gt;
# Calculate interior points: $I = \mathtt{area}/2 - \mathtt{boundary}/2 + 1$&lt;br /&gt;
# Check if $I$ is a perfect square by computing its integer square root and squaring it&lt;br /&gt;
&lt;br /&gt;
Count all quadruples where $I$ is a perfect square.&lt;br /&gt;
&lt;br /&gt;
===Complexity===&lt;br /&gt;
&lt;br /&gt;
The quadruple nested loop runs in $O(m^4)$ time. Pre-computing the GCD table takes $O(m^2 \log \max(a,b))$ time. For $m = 100$, the total number of quadruples is $100^4 = 100{,}000{,}000$, which is feasible in Java with efficient inner-loop operations.&lt;br /&gt;
&lt;br /&gt;
==Solution==&lt;br /&gt;
&lt;br /&gt;
Link: https://git.charlesreid1.com/cs/euler/src/branch/main/java/Problem504.java&lt;br /&gt;
&lt;br /&gt;
==Flags==&lt;br /&gt;
&lt;br /&gt;
{{ProjectEulerFlag}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>