Non-bouncy Numbers
A positive integer is increasing if its digits are non-decreasing from left to right, decreasing if non-increasing, and bouncy otherwise. How many numbers below a googol (10^100) are not bouncy?
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, $134468$.
Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, $66420$.
We shall call a positive integer that is neither increasing nor decreasing a "bouncy" number; for example, $155349$.
As $n$ increases, the proportion of bouncy numbers below $n$ increases such that there are only $12951$ numbers below one-million that are not bouncy and only $277032$ non-bouncy numbers below $10^{10}$.
How many numbers below a googol ($10^{100}$) are not bouncy?
Problem 113: Non-bouncy Numbers
Mathematical Development
Theorem 1 (Counting increasing numbers). The number of positive increasing integers with at most digits is
Proof. An increasing number with at most digits corresponds bijectively to a non-decreasing sequence , where leading zeros represent shorter numbers. The number of such non-decreasing sequences is the number of multisets of size drawn from an alphabet of size 10. By the stars-and-bars theorem, this equals
This count includes the all-zeros sequence , which represents the integer 0, not a positive integer. Subtracting this single case yields .
Theorem 2 (Counting decreasing numbers). The number of positive decreasing integers with at most digits is
Proof. A decreasing number of exactly digits is a non-increasing sequence with and . By reversal, the count of non-increasing sequences of length from equals the count of non-decreasing sequences, which is . Exactly one of these (the all-zeros sequence) has , so the count with is .
Summing over all lengths :
By the hockey-stick (Christmas stocking) identity,
Therefore .
Lemma 1 (Overlap: numbers both increasing and decreasing). The number of positive integers with at most digits that are simultaneously increasing and decreasing is .
Proof. A number is both increasing and decreasing if and only if all its digits are identical, i.e., it is a repdigit. For each digit length , there are exactly 9 positive repdigits: for . The total is .
Theorem 3 (Non-bouncy count by inclusion-exclusion). The number of non-bouncy positive integers below is
Proof. By inclusion-exclusion, the non-bouncy count equals . Substituting:
Corollary 2 (Asymptotic non-bouncy fraction). The fraction of non-bouncy numbers below satisfies
Proof. The leading term of is , which is polynomial in . Since polynomial growth is dominated by exponential growth, the ratio tends to 0.
Editorial
We enumerate the admissible parameter range, discard candidates that violate the derived bounds or arithmetic constraints, and update the final set or total whenever a candidate passes the acceptance test.
Pseudocode
inc = Binomial(n + 9, 9)
dec = Binomial(n + 10, 10)
Return inc + dec - 10 * n - 2
result = 1
For i from 0 to k - 1:
result = result * (n - i) / (i + 1)
Return result
answer = NonBouncyBelow(100)
Complexity Analysis
- Time. arithmetic operations: computing requires 9 multiplications and 9 divisions, and requires 10 of each. With big-integer arithmetic on numbers of digits, each operation costs via FFT-based multiplication, giving total. For , this is negligible.
- Space. : a constant number of big integers, each with digits.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
typedef __int128 lll;
long long binom(int n, int k) {
lll result = 1;
for (int i = 0; i < k; i++)
result = result * (n - i) / (i + 1);
return (long long)result;
}
int main() {
int n = 100;
long long inc = binom(n + 9, 9) - 1;
long long dec = binom(n + 10, 10) - 1 - n;
long long overlap = 9LL * n;
cout << inc + dec - overlap << endl;
return 0;
}
from math import comb
def solve():
n = 100
inc = comb(n + 9, 9) - 1
dec = comb(n + 10, 10) - 1 - n
overlap = 9 * n
print(inc + dec - overlap)
solve()