Bounded Sequences
Let t(n) denote the number of sequences (x_1,..., x_n) of positive integers such that there exists alpha in [2, 3) with x_i = floor(alpha^i) for all i. Given t(10) = 86195 and t(20) = 5227991891, f...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Let $x_1, x_2, \dots, x_n$ be a sequence of length $n$ such that:
$x_1 = 2$
for all $1 < i \le n$: $x_{i - 1} < x_i$
for all $i$ and $j$ with $1 \le i, j \le n$: $(x_i)^j < (x_j + 1)^i$.
There are only five such sequences of length $2$, namely: $\{2,4\}$, $\{2,5\}$, $\{2,6\}$, $\{2,7\}$ and $\{2,8\}$.
There are $293$ such sequences of length $5$; three examples are given below:
$\{2,5,11,25,55\}$, $\{2,6,14,36,88\}$, $\{2,8,22,64,181\}$.
Let $t(n)$ denote the number of such sequences of length $n$.
You are given that $t(10) = 86195$ and $t(20) = 5227991891$.
Find $t(10^{10})$ and give your answer modulo $10^9$.
Problem 319: Bounded Sequences
Mathematical Foundation
Definition. For real , the sequence is the -floor sequence of length . Let count the distinct -floor sequences for .
Lemma 1 (Counting Function ). Define and . Then counts, with appropriate multiplicity, the total number of integer sequences of length consistent with some (before applying Mobius inversion to account for primitivity).
Proof. For each position , the number of possible values of as ranges over is bounded by (the interval contains that many integers). The function sums geometric series counting lattice points under power curves. The difference aggregates these counts.
Theorem 1 (Mobius Inversion Formula). The count of distinct sequences is:
where is the Mobius function.
Proof. A sequence of length arising from may coincide with a sequence of length extended periodically (in terms of the -intervals). The inclusion-exclusion via Mobius inversion removes these overcounts:
Lemma 2 (Matrix Exponentiation for ). is computable in via:
so .
Proof. By induction on . The base case gives , and . For the inductive step, multiplying on the right by :
The identity is verified algebraically.
Theorem 2 (Efficient Summation via Mertens Function). Since takes only distinct values, group terms:
where is the Mertens function and is the range of with .
Proof. Regrouping the sum by distinct values of and using partial sums of .
Lemma 3 (Mertens Function Computation). satisfies:
Sieve for ; compute recursively with memoization for larger arguments. Total time: .
Proof. From , summing over : . Isolating : . The hyperbolic summation trick (grouping by distinct values of ) combined with sieving up to gives complexity.
Verification. , , .
Editorial
t(n) = number of sequences (x_1, …, x_n) where x_i = floor(alpha^i) for some alpha in [2, 3). Formula: t(n) = sum_{k=1}^{n} mu(k) * g(floor(n/k)) where g(m) = G(3,m) - G(2,m), G(v,m) = v * (v^m - 1) / (v - 1) Uses Mobius function prefix sums (Mertens function) and matrix exponentiation. We sieve mu(k) for k <= n^(2/3), compute prefix sums M(k). We then iterate over large arguments, compute M(x) recursively with memoization. Finally, sum all contributions modulo MOD.
Pseudocode
Input: n = 10^10, MOD = 10^9
Output: t(n) mod MOD
Sieve mu(k) for k <= n^(2/3), compute prefix sums M(k)
For large arguments, compute M(x) recursively with memoization:
Enumerate distinct values q = floor(n/k):
Sum all contributions modulo MOD
Return result
Complexity Analysis
- Time: for Mertens function computation. for matrix exponentiations over distinct values. Total: .
- Space: for the sieve and memoization table.
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 319: Bounded Sequences
*
* t(n) = sum_{k=1}^{n} mu(k) * g(floor(n/k))
* where g(m) = G(3,m) - G(2,m), G(v,m) = v*(v^m - 1)/(v-1)
*
* Uses:
* - Sieve for Mobius function prefix sums up to LMT
* - Mertens function via recursive formula with memoization for large values
* - Matrix exponentiation for G(v,m) mod MOD
*
* Answer: 268457129
*/
typedef long long i64;
const i64 N = 10000000000LL; // 10^10
const i64 MOD = 1000000000LL; // 10^9
const int LMT = 10000000; // 10^7
i64 mu_prefix[LMT + 1]; // prefix sum of Mobius function
map<i64, i64> memo_mertens;
// Compute Mertens function M(n) = sum_{k=1}^{n} mu(k), modulo MOD
i64 mertens(i64 n) {
if (n <= LMT) return mu_prefix[n];
if (memo_mertens.count(n)) return memo_mertens[n];
i64 ret = 1; // M(1) = mu(1) = 1
for (i64 i = 2, j; i <= n; i = j) {
j = n / (n / i) + 1;
ret = (ret + MOD - (j - i) % MOD * mertens(n / i) % MOD) % MOD;
}
return memo_mertens[n] = ret;
}
// 2x2 matrix multiplication mod MOD
typedef i64 mat[2][2];
void matmul(mat a, mat b, mat c) {
mat t;
memset(t, 0, sizeof(mat));
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
t[i][k] = (t[i][k] + a[i][j] % MOD * (b[j][k] % MOD)) % MOD;
memcpy(c, t, sizeof(mat));
}
// G(v, x) = v * (v^x - 1) / (v - 1) mod MOD, via matrix exponentiation
// [v 1; 0 1]^x has entry [0][1] = (v^x - 1)/(v - 1)
i64 G(int v, i64 x) {
if (x == 0) return 0;
mat A, B;
A[0][0] = v; A[0][1] = 1;
A[1][0] = 0; A[1][1] = 1;
memset(B, 0, sizeof(B));
B[0][0] = B[1][1] = 1; // identity
for (i64 e = x; e; e >>= 1) {
if (e & 1) matmul(B, A, B);
matmul(A, A, A);
}
return (i64)v % MOD * (B[0][1] % MOD) % MOD;
}
i64 g(i64 x) {
return (G(3, x) - G(2, x) + MOD) % MOD;
}
int main() {
// Sieve Mobius function and compute prefix sums
vector<int> mu_val(LMT + 1, 0);
vector<bool> is_composite(LMT + 1, false);
vector<int> primes;
mu_val[1] = 1;
for (int i = 2; i <= LMT; i++) {
if (!is_composite[i]) {
primes.push_back(i);
mu_val[i] = -1;
}
for (int j = 0; j < (int)primes.size() && (i64)i * primes[j] <= LMT; j++) {
int t = i * primes[j];
is_composite[t] = true;
if (i % primes[j] == 0) {
mu_val[t] = 0;
break;
} else {
mu_val[t] = -mu_val[i];
}
}
}
mu_prefix[0] = 0;
for (int i = 1; i <= LMT; i++)
mu_prefix[i] = (mu_prefix[i - 1] + mu_val[i] % MOD + MOD) % MOD;
// Compute t(N) = sum_{k=1}^{N} mu(k) * g(floor(N/k))
// Group by distinct values of floor(N/k)
i64 ans = 0;
i64 prev_mertens = 0; // M(0) = 0
for (i64 i = 1, j; i <= N; i = j) {
j = N / (N / i) + 1;
i64 cur_mertens = mertens(j - 1);
i64 block_mu_sum = (cur_mertens - prev_mertens + MOD) % MOD;
ans = (ans + block_mu_sum % MOD * g(N / i) % MOD) % MOD;
prev_mertens = cur_mertens;
}
cout << ans % MOD << endl;
return 0;
}
"""
Problem 319: Bounded Sequences
t(n) = number of sequences (x_1, ..., x_n) where x_i = floor(alpha^i)
for some alpha in [2, 3).
Formula: t(n) = sum_{k=1}^{n} mu(k) * g(floor(n/k))
where g(m) = G(3,m) - G(2,m), G(v,m) = v * (v^m - 1) / (v - 1)
Uses Mobius function prefix sums (Mertens function) and matrix exponentiation.
Answer: 268457129
"""
import sys
sys.setrecursionlimit(200000)
MOD = 10**9
N = 10**10
LMT = 10**7
def solve():
# Sieve Mobius function up to LMT
mu_val = [0] * (LMT + 1)
mu_val[1] = 1
is_composite = [False] * (LMT + 1)
primes = []
for i in range(2, LMT + 1):
if not is_composite[i]:
primes.append(i)
mu_val[i] = -1
for p in primes:
if i * p > LMT:
break
is_composite[i * p] = True
if i % p == 0:
mu_val[i * p] = 0
break
else:
mu_val[i * p] = -mu_val[i]
# Prefix sums of Mobius function mod MOD
mu_prefix = [0] * (LMT + 1)
for i in range(1, LMT + 1):
mu_prefix[i] = (mu_prefix[i - 1] + mu_val[i]) % MOD
# Memoized Mertens function for large values
memo = {}
def mertens(n):
if n <= LMT:
return mu_prefix[n]
if n in memo:
return memo[n]
ret = 1 # M(1) = 1
i = 2
while i <= n:
j = n // (n // i) + 1
ret = (ret + MOD - (j - i) % MOD * mertens(n // i) % MOD) % MOD
i = j
memo[n] = ret
return ret
# Matrix exponentiation for G(v, x) = v * (v^x - 1) / (v - 1) mod MOD
def mat_mul(A, B):
return [
[(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % MOD,
(A[0][0] * B[0][1] + A[0][1] * B[1][1]) % MOD],
[(A[1][0] * B[0][0] + A[1][1] * B[1][0]) % MOD,
(A[1][0] * B[0][1] + A[1][1] * B[1][1]) % MOD]
]
def G(v, x):
if x == 0:
return 0
A = [[v, 1], [0, 1]]
B = [[1, 0], [0, 1]] # identity
e = x
while e > 0:
if e & 1:
B = mat_mul(B, A)
A = mat_mul(A, A)
e >>= 1
return v * B[0][1] % MOD
def g(x):
return (G(3, x) - G(2, x) + MOD) % MOD
# Compute t(N) = sum_{k=1}^{N} mu(k) * g(floor(N/k))
ans = 0
prev_m = 0
i = 1
while i <= N:
j = N // (N // i) + 1
cur_m = mertens(j - 1)
block_sum = (cur_m - prev_m + MOD) % MOD
ans = (ans + block_sum * g(N // i)) % MOD
prev_m = cur_m
i = j
print(ans)
if __name__ == "__main__":
solve()