<?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%2F700</id>
	<title>Project Euler/700 - 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%2F700"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Project_Euler/700&amp;action=history"/>
	<updated>2026-06-19T12:20:00Z</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/700&amp;diff=30603&amp;oldid=prev</id>
		<title>Admin: Create Project Euler/700 page with problem statement, Euclidean algorithm approach, and solution link (via create-page on MediaWiki MCP Server)</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Project_Euler/700&amp;diff=30603&amp;oldid=prev"/>
		<updated>2026-06-16T23:31:31Z</updated>

		<summary type="html">&lt;p&gt;Create Project Euler/700 page with problem statement, Euclidean algorithm approach, and solution link (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;
Leonhard Euler was born on 15 April 1707.&lt;br /&gt;
&lt;br /&gt;
Consider the sequence:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
a_n = 1504170715041707 \, n \bmod 4503599627370517&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An element of this sequence is defined to be an Eulercoin if it is strictly smaller than all previously found Eulercoins. For example:&lt;br /&gt;
&lt;br /&gt;
* The first term is &amp;lt;math&amp;gt;1504170715041707&amp;lt;/math&amp;gt;, which is the first Eulercoin.&lt;br /&gt;
* The second term is &amp;lt;math&amp;gt;3008341430083414&amp;lt;/math&amp;gt;, which is greater than the first, so it is not an Eulercoin.&lt;br /&gt;
* The third term is &amp;lt;math&amp;gt;8912517754604&amp;lt;/math&amp;gt;, which is smaller than the first, making it the second Eulercoin.&lt;br /&gt;
&lt;br /&gt;
The sum of the first two Eulercoins is therefore &amp;lt;math&amp;gt;1513083232796311&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Find the sum of all Eulercoins.&lt;br /&gt;
&lt;br /&gt;
==Approach==&lt;br /&gt;
&lt;br /&gt;
===Key Insight===&lt;br /&gt;
&lt;br /&gt;
The sequence &amp;lt;math&amp;gt;a(n) = k n \bmod M&amp;lt;/math&amp;gt; achieves new record minima exactly at the convergents of the continued fraction of &amp;lt;math&amp;gt;k/M&amp;lt;/math&amp;gt;. By the three-distance theorem, these record lows correspond precisely to the odd-indexed remainders in the Euclidean algorithm applied to &amp;lt;math&amp;gt;(M, k)&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
r_1 = k, \; r_2 = M \bmod k, \; r_3, \; r_4, \; r_5, \dots&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Only the odd-indexed steps (&amp;lt;math&amp;gt;r_1, r_3, r_5, \dots&amp;lt;/math&amp;gt;) generate Eulercoins.&lt;br /&gt;
&lt;br /&gt;
===Euclidean Algorithm Walk===&lt;br /&gt;
&lt;br /&gt;
At each odd step &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; with quotient &amp;lt;math&amp;gt;q_i = \lfloor r_i / r_{i+1} \rfloor&amp;lt;/math&amp;gt;, there are exactly &amp;lt;math&amp;gt;q_i&amp;lt;/math&amp;gt; Eulercoins. These Eulercoins form a descending arithmetic progression:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
r_i - j \cdot r_{i+1}, \quad \text{for } j = 1, 2, \dots, q_i&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The sum contributed by this step is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\sum_{j=1}^{q_i} \left( r_i - j \cdot r_{i+1} \right) = q_i \cdot r_i - r_{i+1} \cdot \frac{q_i (q_i + 1)}{2}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Algorithm===&lt;br /&gt;
&lt;br /&gt;
# Initialize &amp;lt;math&amp;gt;\text{sum} = k&amp;lt;/math&amp;gt; (the first Eulercoin, &amp;lt;math&amp;gt;r_1&amp;lt;/math&amp;gt;).&lt;br /&gt;
# Run the Euclidean algorithm on &amp;lt;math&amp;gt;(M, k)&amp;lt;/math&amp;gt;, maintaining &amp;lt;math&amp;gt;(a, b) = (r_i, r_{i+1})&amp;lt;/math&amp;gt; starting with &amp;lt;math&amp;gt;a = k&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b = M \bmod k&amp;lt;/math&amp;gt;.&lt;br /&gt;
# For each step &amp;lt;math&amp;gt;i = 1, 2, 3, \dots&amp;lt;/math&amp;gt;:&lt;br /&gt;
#* Compute quotient &amp;lt;math&amp;gt;q = \lfloor a / b \rfloor&amp;lt;/math&amp;gt; and remainder &amp;lt;math&amp;gt;\text{next} = a \bmod b&amp;lt;/math&amp;gt;.&lt;br /&gt;
#* If &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is odd: add &amp;lt;math&amp;gt;q \cdot a - b \cdot q (q + 1) / 2&amp;lt;/math&amp;gt; to the sum.&lt;br /&gt;
#* Set &amp;lt;math&amp;gt;a = b&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b = \text{next}&amp;lt;/math&amp;gt;, and increment &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Stop when &amp;lt;math&amp;gt;b = 0&amp;lt;/math&amp;gt;. Return the accumulated sum.&lt;br /&gt;
&lt;br /&gt;
===Complexity===&lt;br /&gt;
&lt;br /&gt;
The Euclidean algorithm terminates in &amp;lt;math&amp;gt;O(\log M)&amp;lt;/math&amp;gt; steps — approximately 34 iterations for this problem. All intermediate products fit within a Java &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;, so no overflow handling is needed. The solution runs in about 40 ms.&lt;br /&gt;
&lt;br /&gt;
==Solution==&lt;br /&gt;
&lt;br /&gt;
Link: https://git.charlesreid1.com/cs/euler/src/branch/main/java/Problem700.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>