Convergents of e
Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The square root of \(2\) can be written as an infinite continued fraction.
\[\sqrt {2} = 1 + \dfrac {1}{2 + \dfrac {1}{2 + \dfrac {1}{2 + \dfrac {1}{2 + ...}}}}\]
The infinite continued fraction can be written, \(\sqrt {2} = [1; (2)]\), \((2)\) indicates that \(2\) repeats
Hence the sequence of the first ten convergents for \(\sqrt {2}\) are: \[1, \dfrac {3}{2}, \dfrac {7}{5}, \dfrac {17}{12}, \dfrac {41}{29}, \dfrac {99}{70}, \dfrac {239}{169}, \dfrac {577}{408}, \dfrac {1393}{985}, \dfrac {3363}{2378}, ...\] What is most surprising is that the important mathematical constant,
\(e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, ... , 1, 2k, 1, ...]\). The first ten terms in the sequence of convergents for \(e\) are: \[2, 3, \dfrac {8}{3}, \dfrac {11}{4}, \dfrac {19}{7}, \dfrac {87}{32}, \dfrac {106}{39}, \dfrac {193}{71}, \dfrac {1264}{465}, \dfrac {1457}{536}, ...\] The sum of digits in the numerator of the \(10^{th}\) convergent is \(1 + 4 + 5 + 7 = 17\).
Find the sum of digits in the numerator of the \(100^{th}\) convergent of the continued fraction for \(e\).
Problem 65: Convergents of e
Mathematical Foundation
Theorem 1 (Euler, 1737). The continued fraction expansion of is
where the partial quotients are and for :
Proof. Euler derived this from the generalized continued fraction
using the relationship between and the confluent hypergeometric function. Specifically, consider the series and apply Euler’s method of converting power series to continued fractions. The proof relies on the identity
from which the stated continued fraction for can be derived via equivalence transformations. A complete proof appears in Perron’s Die Lehre von den Kettenbruechen (1929).
Theorem 2 (Convergent Recurrence). The convergents satisfy the recurrence
with initial conditions , , , .
Proof. Define the matrix
We claim that
Base case (): , giving , , , . Since , this is correct.
Inductive step: Assume the product gives the correct matrix. Then
which gives and . To see that , note that replacing by in the matrix product and using the inductive hypothesis on confirms the identity.
Lemma 1 (Coprimality). For all , .
Proof. Taking determinants of the matrix product:
Since , we have .
Lemma 2 (Growth Rate). The numerator has approximately digits, which for the continued fraction yields about 57—58 digits.
Proof. From the recurrence , so . By induction, . The partial quotients for at indices are (for up to 98), contributing . The remaining 67 terms contribute each (except ). Total: . The actual numerator has 58 digits due to the additive term accumulating additional magnitude.
Editorial
We use Euler’s explicit pattern for the continued fraction of to determine the first partial quotients. The numerator of the convergents is then obtained from the standard recurrence, so only the two previous numerators need to be retained throughout the computation. Once the numerator of the th convergent has been reached, we sum its decimal digits.
Pseudocode
Determine the partial quotients of $e$ from Euler's pattern:
the first term is 2
every third later term is an even number
all remaining terms are 1
Initialize the recurrence with the two starting numerators.
Advance through the first 100 convergents:
form the next numerator from the current partial quotient
then shift the two stored numerators forward
After the last update, compute the decimal digit sum of the current numerator.
Return that sum.
Complexity Analysis
Time: The algorithm computes 100 iterations of the recurrence. Each iteration involves one big-integer multiplication and one big-integer addition. Since has digits, each arithmetic operation costs with schoolbook multiplication (or with FFT-based multiplication, though unnecessary here). Total: .
Space: for storing three big integers (, , ).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
// Simple big integer using vector of digits (least significant first)
struct BigInt {
vector<int> d; // digits, d[0] is least significant
BigInt(int x = 0) {
if (x == 0) d.push_back(0);
while (x > 0) { d.push_back(x % 10); x /= 10; }
}
BigInt operator+(const BigInt& o) const {
BigInt res;
res.d.clear();
int carry = 0;
for (int i = 0; i < (int)max(d.size(), o.d.size()) || carry; i++) {
int s = carry;
if (i < (int)d.size()) s += d[i];
if (i < (int)o.d.size()) s += o.d[i];
res.d.push_back(s % 10);
carry = s / 10;
}
return res;
}
BigInt operator*(int x) const {
BigInt res;
res.d.clear();
long long carry = 0;
for (int i = 0; i < (int)d.size() || carry; i++) {
long long s = carry;
if (i < (int)d.size()) s += (long long)d[i] * x;
res.d.push_back(s % 10);
carry = s / 10;
}
while (res.d.size() > 1 && res.d.back() == 0) res.d.pop_back();
return res;
}
int digit_sum() const {
int s = 0;
for (int x : d) s += x;
return s;
}
};
int main() {
// Continued fraction of e: [2; 1, 2, 1, 1, 4, 1, 1, 6, ...]
// a[0] = 2, a[k] for k>=1: if k%3==2 then 2*(k+1)/3 else 1
auto a = [](int k) -> int {
if (k == 0) return 2;
if (k % 3 == 2) return 2 * (k + 1) / 3;
return 1;
};
// Compute 100th convergent (index 99)
BigInt h_prev2(1); // h_{-1} = 1
BigInt h_prev1(a(0)); // h_0 = a_0 = 2
for (int i = 1; i <= 99; i++) {
BigInt h_new = h_prev1 * a(i) + h_prev2;
h_prev2 = h_prev1;
h_prev1 = h_new;
}
cout << h_prev1.digit_sum() << endl;
return 0;
}
"""
Problem 65: Convergents of e
Find the sum of digits in the numerator of the 100th convergent
of the continued fraction for e.
"""
def solve():
# Continued fraction of e: [2; 1, 2, 1, 1, 4, 1, 1, 6, ...]
def a(k):
if k == 0:
return 2
if k % 3 == 2:
return 2 * (k + 1) // 3
return 1
# Convergent recurrence: h_n = a_n * h_{n-1} + h_{n-2}
h_prev2 = 1 # h_{-1}
h_prev1 = a(0) # h_0
for i in range(1, 100):
h_new = a(i) * h_prev1 + h_prev2
h_prev2 = h_prev1
h_prev1 = h_new
# h_prev1 is now h_99, the numerator of the 100th convergent
return sum(int(d) for d in str(h_prev1))
answer = solve()
assert answer == 272
print(answer)