Tribonacci Non-divisors
The Tribonacci sequence T_n is defined by T_1 = T_2 = T_3 = 1 and T_n = T_(n-1) + T_(n-2) + T_(n-3) for n > 3. Find the 124th odd number that does not divide any Tribonacci number.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The sequence \(1, 1, 1, 3, 5, 9, 17, 31, 57, 105, 193, 355, 653, 1201, \dots \)
is defined by \(T_1 = T_2 = T_3 = 1\) and \(T_n = T_{n - 1} + T_{n - 2} + T_{n - 3}\).
It can be shown that \(27\) does not divide any terms of this sequence.
In fact, \(27\) is the first odd number with this property.
Find the \(124^{th}\) odd number that does not divide any terms of the above sequence.
Problem 225: Tribonacci Non-divisors
Mathematical Foundation
Theorem 1 (All Tribonacci Numbers Are Odd). For all , is odd.
Proof. Base cases: are odd. Inductive step: assume are all odd. Then , which is odd. By strong induction, all are odd.
Theorem 2 (Pure Periodicity Modulo ). For any positive integer , the Tribonacci sequence modulo is purely periodic.
Proof. Consider the sequence of triples . There are possible triples, so by the pigeonhole principle, some triple must repeat: there exist with
The recurrence is invertible: . Therefore we can extend the sequence backwards uniquely. Applying the inverse recurrence times from the repeated triple shows that . Hence the sequence is purely periodic with period dividing .
Lemma 1 (Period Bound). The period of the Tribonacci sequence modulo is at most .
Proof. There are possible triples of residues, so a repetition must occur within steps.
Theorem 3 (Divisibility Criterion). An odd number divides some Tribonacci number if and only if appears in one complete period of the sequence .
Proof. () If , then appears in the sequence. () If appears in one period, then since the sequence is purely periodic, for some . Conversely, if never appears in one full period, the pure periodicity guarantees it never appears at all.
Lemma 2 (Cycle Detection). To test whether appears in the period, compute starting from until either (divisor found) or the triple returns to (non-divisor confirmed).
Proof. By Theorem 2, the sequence is purely periodic starting from . If recurs, one full period has been traversed. If was not encountered, it never will be.
Editorial
T(1) = T(2) = T(3) = 1, T(n) = T(n-1) + T(n-2) + T(n-3). For each odd m, compute T(n) mod m. If 0 never appears in the cycle, then m is a non-divisor. We loop.
Pseudocode
while true
loop
Complexity Analysis
- Time: For each candidate , the cycle detection runs for at most iterations, but in practice the period is much shorter (typically ). We test odd numbers up to approximately 2009. Total work is bounded by where is the actual period, empirically .
- Space: per candidate (only three residues stored).
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(){
// Find the 124th odd number that does not divide any Tribonacci number.
// T(1) = T(2) = T(3) = 1, T(n) = T(n-1) + T(n-2) + T(n-3).
// For each odd m, compute T(n) mod m until 0 is found or cycle detected.
int target = 124;
int count = 0;
for(int m = 1; ; m += 2){
// Check if m divides any Tribonacci number
int a = 1 % m, b = 1 % m, c = 1 % m;
bool divides = false;
// Check if m = 1 (divides everything)
if(m == 1){
// T(1) = 1, and 1 divides 1. So 1 divides a tribonacci number.
continue;
}
// Iterate through the cycle
for(long long iter = 0; iter < (long long)m * m * m + 10; iter++){
int next = (a + b + c) % m;
a = b;
b = c;
c = next;
if(c == 0){
divides = true;
break;
}
// Check if we've returned to (1, 1, 1)
if(a == 1 % m && b == 1 % m && c == 1 % m){
break;
}
}
if(!divides){
count++;
if(count == target){
cout << m << endl;
return 0;
}
}
}
return 0;
}
"""
Problem 225: Tribonacci Non-divisors
Find the 124th odd number that does not divide any Tribonacci number.
T(1) = T(2) = T(3) = 1, T(n) = T(n-1) + T(n-2) + T(n-3).
For each odd m, compute T(n) mod m. If 0 never appears in the cycle,
then m is a non-divisor.
"""
def does_not_divide_any_tribonacci(m):
"""Return True if m does not divide any Tribonacci number."""
if m == 1:
return False # 1 divides T(1) = 1
a, b, c = 1 % m, 1 % m, 1 % m
for _ in range(m * m * m + 10):
nxt = (a + b + c) % m
a, b, c = b, c, nxt
if c == 0:
return False # m divides some T(n)
if a == 1 and b == 1 and c == 1:
return True # cycle completed, 0 never appeared
return True # shouldn't reach here for reasonable m
def solve():
target = 124
count = 0
m = 1
while True:
if does_not_divide_any_tribonacci(m):
count += 1
if count == target:
print(m)
return
m += 2
if __name__ == "__main__":
solve()