Problem

Source: Brazilian Mathematical Olympiad 2023, Level 3, Problem 6

Tags: number theory, Sequence, prime numbers



For a positive integer $k$, let $p(k)$ be the smallest prime that does not divide $k$. Given a positive integer $a$, define the infinite sequence $a_0, a_1, \ldots$ by $a_0 = a$ and, for $n > 0$, $a_n$ is the smallest positive integer with the following properties: • $a_n$ has not yet appeared in the sequence, that is, $a_n \neq a_i$ for $0 \leq i < n$; • $(a_{n-1})^{a_n} - 1$ is a multiple of $p(a_{n-1})$. Prove that every positive integer appears as a term in the sequence, that is, for every positive integer $m$ there is $n$ such that $a_n = m$.