2011 Nines
For integers 1 <= p < q with p + q <= 2011, let C(p,q,n) be the count of consecutive nines at the start of the fractional part of (sqrt(p) + sqrt(q))^2n. Let N(p,q) be the minimal n with C(p,q,n) >...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Consider the real number \(\sqrt 2 + \sqrt 3\).
When we calculate the even powers of \(\sqrt 2 + \sqrt 3\) we get:
\((\sqrt 2 + \sqrt 3)^2 = 9.898979485566356 \cdots \)
\((\sqrt 2 + \sqrt 3)^4 = 97.98979485566356 \cdots \)
\((\sqrt 2 + \sqrt 3)^6 = 969.998969071069263 \cdots \)
\((\sqrt 2 + \sqrt 3)^8 = 9601.99989585502907 \cdots \)
\((\sqrt 2 + \sqrt 3)^{10} = 95049.999989479221 \cdots \)
\((\sqrt 2 + \sqrt 3)^{12} = 940897.9999989371855 \cdots \)
\((\sqrt 2 + \sqrt 3)^{14} = 9313929.99999989263 \cdots \)
\((\sqrt 2 + \sqrt 3)^{16} = 92198401.99999998915 \cdots \)
It looks as if the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing.
In fact it can be proven that the fractional part of \((\sqrt 2 + \sqrt 3)^{2 n}\) approaches \(1\) for large \(n\).
Consider all real numbers of the form \(\sqrt p + \sqrt q\) with \(p\) and \(q\) positive integers and \(p < q\), such that the fractional part of \((\sqrt p + \sqrt q)^{ 2 n}\) approaches \(1\) for large \(n\).
Let \(C(p,q,n)\) be the number of consecutive nines at the beginning of the fractional part of \((\sqrt p + \sqrt q)^{ 2 n}\).
Let \(N(p,q)\) be the minimal value of \(n\) such that \(C(p,q,n) \ge 2011\).
Find \(\displaystyle \sum N(p,q) \,\, \text { for } p+q \le 2011\).
Problem 318: 2011 Nines
Mathematical Foundation
Lemma 1 (Conjugate Pair). Define and . Then and are roots of:
Proof. We have and , both integers. The quadratic with roots is .
Theorem 1 (Integer Power Sums). For all , .
Proof. By Newton’s identity, the power sums of roots of a monic polynomial with integer coefficients are integers. Concretely, satisfies the recurrence:
By induction, each . Since and , we have .
Lemma 2 (Finiteness Condition). is finite if and only if:
- , equivalently , equivalently , and
- is not a perfect square (so ).
Proof. If is a perfect square, then , so and is itself an integer (no fractional nines). If is not a perfect square and , then where and , so , giving arbitrarily many nines. If or , the fractional part does not converge to 1.
Theorem 2 (Counting Consecutive Nines). When and :
Proof. The fractional part is . The number of leading nines in a decimal equals . More precisely, , since and the leading nines count is .
Corollary (Formula for ). The minimal with is:
Proof. iff iff . The smallest such integer is the ceiling.
Editorial
For 1 <= p < q with p+q <= 2011, where pq is not a perfect square and |sqrt(q) - sqrt(p)| < 1: beta = (sqrt(p) - sqrt(q))^2 = p + q - 2*sqrt(pq) N(p,q) = ceil(-2011 / log10(beta)) Find the sum of N(p,q) over all valid pairs. We return total.
Pseudocode
Input: bound = 2011, target = 2011
Output: sum of N(p,q) over valid pairs
total = 0
For p = 1 to 1005:
Return total
Complexity Analysis
- Time: where . Total: , negligible.
- Space: .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 318: 2011 Nines
*
* For p < q with p+q <= 2011, pq not a perfect square, and (sqrt(q)-sqrt(p)) < 1:
* beta = p + q - 2*sqrt(pq)
* N(p,q) = ceil(-2011 / log10(beta))
*
* Sum all N(p,q).
*/
int main(){
const int L = 2011;
long long total = 0;
for(int p = 1; p < L; p++){
double sp = sqrt((double)p);
int max_q = min(L - p, (int)((sp + 1.0) * (sp + 1.0)) + 1);
for(int q = p + 1; q <= max_q; q++){
if(p + q > L) break;
// Check if pq is a perfect square
long long pq = (long long)p * q;
long long sq = (long long)sqrt((double)pq);
// Adjust for floating point
while(sq * sq > pq) sq--;
while((sq + 1) * (sq + 1) <= pq) sq++;
if(sq * sq == pq) continue;
double beta = (double)p + (double)q - 2.0 * sqrt((double)pq);
if(beta <= 0.0 || beta >= 1.0) continue;
double n = -2011.0 / log10(beta);
long long N = (long long)ceil(n - 1e-9); // ceil with small tolerance
// More careful: use exact ceil
N = (long long)ceil(n);
// Handle floating point: if N * (-log10(beta)) is very close to 2011
// we need to be careful. For safety:
if((double)N * (-log10(beta)) < 2011.0 - 1e-9) N++;
total += N;
}
}
cout << total << endl;
return 0;
}
"""
Problem 318: 2011 Nines
For 1 <= p < q with p+q <= 2011, where pq is not a perfect square and
|sqrt(q) - sqrt(p)| < 1:
beta = (sqrt(p) - sqrt(q))^2 = p + q - 2*sqrt(pq)
N(p,q) = ceil(-2011 / log10(beta))
Find the sum of N(p,q) over all valid pairs.
"""
from math import sqrt, log10, ceil, isqrt
def solve():
L = 2011 # both the bound on p+q and the number of nines required
total = 0
for p in range(1, L):
sp = sqrt(p)
max_q = min(L - p, int((sp + 1)**2) + 1)
for q in range(p + 1, max_q + 1):
if p + q > L:
break
# Check if pq is a perfect square
pq = p * q
sq_pq = isqrt(pq)
if sq_pq * sq_pq == pq:
continue
beta = p + q - 2 * sqrt(pq)
if beta <= 0 or beta >= 1:
continue
N = ceil(-L / log10(beta))
total += N
print(total)
if __name__ == "__main__":
solve()