TITLE: Function that produces primes
QUESTION [65 upvotes]: For any $n\geq 2$ consider the recursion
\begin{align*}
a(0,n)&=n;\\
a(m,n)&=a(m-1,n)+\operatorname{gcd}(a(m-1,n),n-m),\qquad m\geq 1. 
\end{align*}
I conjecture that $a(n-1,n)$ is always prime.
To verify it one may use this simple PARI prog:
a(n)=my(A=n, B); for(i=1, n-1, B=n-i; A+=gcd(A,B)); A;

The sequence begins
$$3, 5, 7, 11, 11, 13, 17, 17, 19, 23, 23, 29, 29, 29, 31, 41, 53, 37, 41, 41$$
The sequence is not in the OEIS.
Is there a way to prove it?

REPLY [23 votes]: Extended comment, generalizing @IlyaBogdanov's comment about $2n-1$. Fix $n$ and let $$x_m = a(m, n) + n - m - 1.$$ Then $(x_m)$ obeys the similar recurrence
$$
  x_m = x_{m-1} + \gcd(x_{m-1}, n-m) - 1.
$$
Also $x_0 = 2n-1$ and $x_{n-1} = a(n-1, n)$.
Now from the recurrence it is clear that if $x_m$ is prime for any value of $m < n$ then $x_{n-1} = x_m$. While $x_m$ is not prime it is increasing slowly and erratically, so it has plenty of chances to hit a prime.