Prime Generating Recurrence


Prime Generating Recurrence

Simon
We're looking at a recurrence today that does something pretty surprising. It's defined as R(n) = R(n-1) + gcd(n, R(n-1)). So each term is the previous term plus the greatest common divisor of the index and that previous term.

Corey
That's like a warped Fibonacci, but only needs one initial term. You mentioned the initial term is usually chosen as 7. Why not something else?

Simon
7 was just the first one that worked to show the behavior. If you start with 7, the first few terms are 7, 8, 9, 10 — all just stepping by 1 because the gcds are 1. But then at n=5, gcd(5,10)=5, so the sequence jumps to 15. Then at n=6, gcd(6,15)=3, jump to 18. Then back to 1s for a bit. So the interesting part is those jumps.

Corey
And when you collect those gcds that aren't 1, they turn out to be primes! That's the first big surprise. Let's list them: 5, 3, 11, 3, 23, 3, 47, 3, 101, 7, 3, 11, 3, 13, ... So except for the first 5, all are primes? But wait, 3 appears over and over.

Simon
Exactly. And notice the doubling pattern: 5 leads to 11, 11 to 23, 23 to 47, but 47 to 101 isn't exactly double plus one. Actually 2*47+1=95, which isn't prime and doesn't appear. So the pattern isn't about the primes themselves. It's about the indices where those primes appear.

Corey
Right, if you plot the indices of the nontrivial gcds on a logarithmic scale, you see clusters. The clusters are spaced such that the average index of one cluster is about double the average of the previous cluster. That's why the runs of 1s roughly double each time.

Simon
And within each cluster, the primes are close together. The first prime in a cluster seems to come from the index of the previous prime. For example, the first cluster starts at index 5, then the next cluster starts at index 11, which is 2*6-1. Then 23 from 2*12-1, 47 from 2*24-1, and 101 from 2*51-1? But 51 is the index of the previous prime? Actually 51 is the index of the 3 before 101, not the prime 3. So it's not the prime, it's the index.

Corey
That's the key insight. For the beginning of a cluster, the first prime is 2n-1 where n is the index of the previous prime. That gives 101 from 51, and 101 is prime. But what about primes inside a cluster? Take the cluster starting with 101. At index 102, we get 2*102-1=203, whose smallest prime divisor is 7. And sure enough, the next prime is 7. So the rule is: the next nontrivial gcd is the smallest prime divisor of 2n-1.

Simon
And the number of steps until it appears is (p-1)/2. For p=7, that's 3, so the prime 7 appears at index 102+3? Actually check: at index 101, p=101, so the next nontrivial gcd appears after (101-1)/2=50 steps, at index 151? But the cluster has 101, then 102? Wait, we need to be careful. The rule says: from current index n, the next prime p appears at index n + (p-1)/2. So from 101, p=101, so i=50, so the next prime appears at index 151. That matches the data: 101 then 151? Actually the next prime after 101 in the cluster is 7 at index 102? No, that's not right. Let's reexamine.

Corey
I think we need to distinguish between the prime at the start of a cluster and the primes within. The theorem states that whenever R(n)=3n, then the next nontrivial gcd is the smallest prime divisor of 2n-1, and it appears after (p-1)/2 steps. At the start of a cluster, we have R(n)=3n, and 2n-1 is prime, so p=2n-1, and the next prime appears after n-1 steps, which is huge. But inside a cluster, R(n) also satisfies R(n)=3n? Actually that's the condition that holds at the beginning of a cluster and is preserved after each prime. So the theorem applies repeatedly.

Simon
Right, so the condition R(n)=3n is crucial. For example, at n=467, R(467)=1401=3*467. Then 2*467-1=933, smallest prime divisor is 3, so the next prime is 3 and appears after (3-1)/2=1 step, so at n=468. And indeed 3 appears there. Then at n=468, R(468)=? It turns out R(468)=1404=3*468, so the condition holds again. Then 2*468-1=935, smallest prime divisor is 5, so the next prime is 5 after 2 steps, at n=470. And so on. This explains the entire cluster.

Corey
So the theorem shows that the recurrence generates primes. But is it useful for finding large primes? Not really. To get a 10-digit prime, you'd need to run the recurrence for about 500 million steps, because the run of 1s before it appears is roughly half the prime. And using the shortcut requires checking if 2n-1 is prime, which is the same difficulty.

Simon
Still, it's a beautiful connection. The primes appear in clusters because when 2n-1 is composite, its smallest prime divisor is small, so the next prime comes quickly. But when 2n-1 is prime, the next prime is far away, starting a new cluster. And we also see that 2 never appears because 2n-1 is odd. After many steps, all primes except 2 appear? Not necessarily; after 10,000 steps, the smallest missing prime is 587. It's an open question whether every prime eventually appears, though there's progress that infinitely many distinct primes do appear.

Corey
And what about the initial term? If we start with 1, the sequence just counts up by 1 forever, so no primes. Starting with 2 or 3 gives boring sequences too. But starting with 4, after a few steps it merges with the sequence starting with 7. And starting with 532, we get some non-prime gcds at first, but eventually the sequence reaches the condition R(n)=3n, and from then on only primes. It's conjectured that any initial term at least 4 will eventually reach that state.

Simon
And there's a fascinating variant by Benoit Cloitre that uses the least common multiple instead of the greatest common divisor: C(n)=C(n-1)+lcm(n, C(n-1)). Starting with 1, the lcms are never 1, so the sequence grows fast. But if you look at the ratio (C(n)/C(n-1))-1, that number is always prime or 1! And that hasn't been proven yet. It's connected to a deep problem about primes in arithmetic progressions.

Corey
So we have two simple recurrences, both generating primes in mysterious ways. The first one we now understand fully thanks to the theorem, but the second one remains a tantalizing open problem. It just shows how much hidden structure there is in elementary number theory.

Simon
Absolutely. And that's what makes these recurrences so much fun to explore. Thanks for joining me, Corey, and we'll see you next time with the full proof of the theorem.

Ask anything
We've read this whole study set, so questions about it get the best answers.