Zeckendorf Representation Uniqueness
By Zeckendorf's theorem, every positive integer n has a unique representation as a sum of non-consecutive Fibonacci numbers. Let z(n) denote the number of Fibonacci summands in this representation....
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Given a pair
Given two such pairs

Shown above are two examples, as viewed from above the cube. That is, we see the paths projected onto the
Define
Let
Find
Problem 975: Zeckendorf Representation Uniqueness
Mathematical Foundation
Definition 1 (Fibonacci Numbers). Define , and for . (Equivalently, in the standard indexing: here equals in the convention.)
Theorem 1 (Zeckendorf, 1972). Every positive integer can be uniquely written as
Proof.
Existence (by strong induction on ): For , the representation is trivial. Suppose all integers less than have a valid representation. Let be the largest Fibonacci number with . If , we are done. Otherwise . Since , we have . By the inductive hypothesis, has a Zeckendorf representation using Fibonacci numbers at most (since implies the largest term is at most ). Prepending gives a valid non-consecutive representation of .
Uniqueness (by strong induction on ): Suppose are two valid representations with and (all indices differing by at least 2). We claim . If , then:
But by the identity (telescoping from ), the right side is at most . This contradicts . By symmetry, is also impossible, so . Canceling and applying the inductive hypothesis to gives and for all .
Lemma 1 (Greedy Algorithm Correctness). The greedy algorithm --- repeatedly subtracting the largest Fibonacci number not exceeding the remainder --- produces the Zeckendorf representation.
Proof. The existence proof above is constructive via the greedy algorithm. By uniqueness (Theorem 1), this must yield the Zeckendorf representation.
Theorem 2 (Average Number of Terms). Let . The average value of for satisfies
as .
Proof. (Sketch.) The Zeckendorf representation induces a bijection between and binary strings of length with no consecutive 1s (the “Fibonacci numeral system”). The number of 1-bits in a random such string has mean by transfer matrix eigenvalue analysis. Since , we get , giving the stated asymptotic.
Editorial
Compute the sum of z(n) for n = 1 to 10^6, where z(n) is the number of terms in the Zeckendorf (greedy Fibonacci) representation of n. Every positive integer has a unique representation as a sum of non-consecutive Fibonacci numbers (Zeckendorf’s theorem). z(n) counts how many Fibonacci numbers are used. We precompute Fibonacci numbers up to N. We then fib = [1, 2, 3, 5, 8, 13, …] with fib[last] >= N. Finally, find largest fib[k] <= remainder.
Pseudocode
Precompute Fibonacci numbers up to N
fib = [1, 2, 3, 5, 8, 13, ...] with fib[last] >= N
Find largest fib[k] <= remainder
Complexity Analysis
- Time: . For each of the integers, the greedy decomposition uses at most steps. For , .
- Space: for the Fibonacci table (about 30 entries for ).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
const int N = 1000000;
vector<long long> fibs = {1, 2};
while (fibs.back() < N) fibs.push_back(fibs[fibs.size()-1]+fibs[fibs.size()-2]);
long long total = 0;
for (int n = 1; n <= N; n++) {
int rem = n, cnt = 0;
for (int i = fibs.size()-1; i >= 0; i--)
if (fibs[i] <= rem) { rem -= fibs[i]; cnt++; }
total += cnt;
}
cout << total << endl;
return 0;
}
"""
Problem 975: Zeckendorf Representation
Compute the sum of z(n) for n = 1 to 10^6, where z(n) is the number of terms
in the Zeckendorf (greedy Fibonacci) representation of n.
Every positive integer has a unique representation as a sum of non-consecutive
Fibonacci numbers (Zeckendorf's theorem). z(n) counts how many Fibonacci numbers
are used.
Key results:
- Greedy algorithm: subtract largest Fibonacci number <= n, repeat
- The representation never uses two consecutive Fibonacci numbers
- z(n) grows roughly as log_phi(n) on average
- answer = sum of z(n) for n = 1..10^6
Methods:
1. build_fibonacci — generate Fibonacci numbers up to N
2. zeckendorf_count — greedy Fibonacci decomposition, return term count
3. zeckendorf_decompose — full decomposition returning the Fibonacci terms
4. average_z_by_range — mean z(n) over ranges for growth analysis
"""
from collections import Counter
def build_fibonacci(N):
"""Return list of Fibonacci numbers (starting 1, 2, 3, 5, ...) up to N."""
fibs = [1, 2]
while fibs[-1] < N:
fibs.append(fibs[-1] + fibs[-2])
return fibs
def zeckendorf_count(n, fibs):
"""Number of Fibonacci numbers in Zeckendorf representation of n."""
c = 0
for f in reversed(fibs):
if f <= n:
n -= f
c += 1
return c
def zeckendorf_decompose(n, fibs):
"""Return the list of Fibonacci numbers used in the Zeckendorf representation."""
terms = []
for f in reversed(fibs):
if f <= n:
n -= f
terms.append(f)
return terms
def average_z_by_range(N, fibs, num_bins=50):
"""Compute mean z(n) in equal-sized bins across [1, N]."""
bin_size = N // num_bins
bin_centers = []
bin_means = []
for i in range(num_bins):
lo = i * bin_size + 1
hi = (i + 1) * bin_size
total = sum(zeckendorf_count(n, fibs) for n in range(lo, hi + 1))
bin_centers.append((lo + hi) / 2)
bin_means.append(total / bin_size)
return bin_centers, bin_means
# Verification
_fibs = build_fibonacci(100)
# 1 = F(1): z=1; 2 = F(2): z=1; 3 = F(3): z=1; 4 = F(3)+F(1) = 3+1: z=2
# 5 = F(4): z=1; 6 = F(4)+F(1) = 5+1: z=2; 7 = F(4)+F(2) = 5+2: z=2
# 8 = F(5): z=1; 10 = 8+2: z=2; 11 = 8+3: z=2; 12 = 8+3+1: z=3
assert zeckendorf_count(1, _fibs) == 1
assert zeckendorf_count(4, _fibs) == 2
assert zeckendorf_count(8, _fibs) == 1
assert zeckendorf_count(12, _fibs) == 3
assert zeckendorf_decompose(12, _fibs) == [8, 3, 1]
# No consecutive Fibonacci numbers in decomposition
for test_n in [20, 50, 99]:
terms = zeckendorf_decompose(test_n, _fibs)
fib_set = set(_fibs)
for i in range(len(terms) - 1):
idx_a = _fibs.index(terms[i])
idx_b = _fibs.index(terms[i + 1])
assert abs(idx_a - idx_b) >= 2, f"Consecutive Fibs in decomposition of {test_n}"
# Main computation
N = 10 ** 6
fibs = build_fibonacci(N)
total = sum(zeckendorf_count(n, fibs) for n in range(1, N + 1))
print(total)
# Visualization — 4-panel figure