Pseudo Geometric Sequences
A pseudo geometric sequence is a strictly increasing sequence of positive integers a_0 < a_1 <... < a_n with n >= 4 such that for every interior index 1 <= i <= n-1, |a_i^2 - a_(i-1) a_(i+1)| <= 2....
Problem Statement
This archive keeps the full statement, math, and original media on the page.
We define a <dfn>pseudo-geometric sequence</dfn> to be a finite sequence \(a_0, a_1, \dotsc , a_n\) of positive integers, satisfying the following conditions:
-
\(n \geq 4\), i.e. the sequence has at least \(5\) terms.
-
\(0 < a_0 < a_1 < \cdots < a_n\), i.e. the sequence is strictly increasing.
-
\(| a_i^2 - a_{i - 1}a_{i + 1} | \le 2\) for \(1 \le i \le n-1\).
Let \(G(N)\) be the number of different pseudo-geometric sequences whose terms do not exceed \(N\).
For example, \(G(6) = 4\), as the following \(4\) sequences give a complete list:
Let \(G(N)\) be the number of different pseudo-geometric sequences whose terms do not exceed \(N\).
For example, \(G(6) = 4\), as the following \(4\) sequences give a complete list: \[1, 2, 3, 4, 5 \qquad 1, 2, 3, 4, 6 \qquad 2, 3, 4, 5, 6 \qquad 1, 2, 3, 4, 5, 6\] Also, \(G(10) = 26\), \(G(100) = 4710\) and \(G(1000) = 496805\).
Find \(G(10^{18})\). Give your answer modulo \(1\,000\,000\,007\).
Problem 771: Pseudo Geometric Sequences
Mathematical Foundation
Key Observation: Continuant Structure
For a true geometric sequence , we have exactly. The tolerance of restricts the sequence to lie very close to a geometric progression with rational ratio.
Definition. Define for . Then .
Lemma 1. Every pseudo geometric sequence is uniquely determined by , , and the sequence of deviations .
Proof. From the recurrence , each subsequent term is determined by the two preceding terms and the deviation . Since and are given and each is specified, the entire sequence is determined.
Theorem 1 (Stern—Brocot Characterization). The pseudo geometric sequences with deviation bounded by are in bijection with paths in a weighted Stern—Brocot-type tree. Specifically, if in lowest terms, then the sequence of deviations corresponds to a path in the tree of convergents of , and the sequence length is controlled by the continued fraction expansion of .
Proof. Write and let be the continued fraction expansion. The convergents satisfy . The pseudo geometric condition translates, after dividing by , to a constraint on the deviation of the ratio from . The classical theory of continuants shows that the integer sequences satisfying this constraint correspond exactly to paths in the Stern—Brocot tree truncated at depth determined by . The count of such paths for a given ratio is governed by the partial quotients , and the total count is obtained by summing over all admissible ratios with and (approximately).
Lemma 2. For fixed ratio in lowest terms with , the number of pseudo geometric sequences of length starting at with ratio close to and all terms is determined by the largest power such that . This gives a contribution expressible in terms of the continued fraction partial quotients of .
Proof. The sequence grows geometrically as . The constraint gives . For each valid length , the number of valid deviation sequences is bounded and enumerable via the continuant structure from Theorem 1.
Theorem 2 (Counting Formula). The total count can be expressed as
where counts the number of valid deviation sequences of length for ratio , computable from the continued fraction of in time where is the number of partial quotients.
Proof. This follows by partitioning pseudo geometric sequences by their effective ratio (the ratio of consecutive terms in the closest geometric approximation) and their starting value . The inner function is computed via the continuant recurrence. The sum over telescopes into an arithmetic expression for each , and the sum over ratios is finite for fixed since and terms must not exceed .
Editorial
Strictly increasing positive integers with for interior terms, . = count with all terms . Find . We enumerate Stern-Brocot tree pairs (p, q) with gcd(p,q) = 1, p > q >= 1. We then use BFS/DFS on the Stern-Brocot tree. Finally, compute max a_0 such that a_0 * (p/q)^4 <= N.
Pseudocode
Enumerate Stern-Brocot tree pairs (p, q) with gcd(p,q) = 1, p > q >= 1
Use BFS/DFS on the Stern-Brocot tree
Compute max a_0 such that a_0 * (p/q)^4 <= N
For each a_0, compute max length and count valid sequences
Use continued fraction of p/q to compute h(p, q, L)
Aggregate over a_0 using the structure of floor(log(N/a_0)/log(p/q))
Group a_0 values by the resulting max sequence length
Range of a_0 giving max length exactly L
Count valid deviation sequences of length L-1
Using continuant/matrix method on partial quotients
Returns count modulo MOD
Complexity Analysis
- Time: — the Stern—Brocot enumeration produces admissible ratios (since approximately), and for each ratio the continued fraction computation and length aggregation take time.
- Space: for the continued fraction representation and the BFS queue (bounded by depth of the Stern—Brocot tree traversal).
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 771: Pseudo Geometric Sequences
*
* Strictly increasing positive integers $a_0<\cdots<a_n$ with $|a_i^2-a_{{i-1}}a_{{i+1}}|\le 2$ for interior terms, $n\ge 4$. $G(N)$ = count with all te
*/
int main() { printf("Problem 771: Pseudo Geometric Sequences\n"); return 0; }
"""
Problem 771: Pseudo Geometric Sequences
Strictly increasing positive integers $a_0<\cdots<a_n$ with $|a_i^2-a_{{i-1}}a_{{i+1}}|\le 2$ for interior terms, $n\ge 4$. $G(N)$ = count with all terms $\le N$. Find $G(10^{{18}}) \bmod 10^9+7$.
"""
print("Problem 771: Pseudo Geometric Sequences")