Let ℓ be the length of the cycle of the sequence a,a2,a3,… mod c. Thus
aℓ+ℓk≡aℓ(modc)(∗)
for all positive integer k and ℓ large enough.
Let d=gcd(ℓ,c). The multiples of ℓ mod c are the multiples of d. Let's prove that if c>1 then d<c. Since d divides c, d≤c.
Suppose that d=c. So c divides ℓ. Note that it's not possible that two equal remainders appear in the same cycle, because a′≡a′(modc) implies a′c≡a′c(modc), that is, i−j is multiple of ℓ, contradiction. Hence the length of the cycle of a,a2,a3,… mod c does not exceed c. Thus, if c divides ℓ, c=ℓ. This means that c divides some an and also every bigger power of a. Hence, ℓ=1 and c=1.
The problem now goes by induction on c. It is obvious for c=1. Suppose that c>1 and that the result is true for every positive integer less than c. Then it is true for d, because d<c. By the induction hypothesis, there are sufficiently large n0,n1,n2,…,nd−1 such that
ani+ni≡i(modd)
for every i=0,1,2,…,d−1.
Let b=qd+r, with 0≤r<d. So, from anr+nr=r+md and (∗),
anr+ℓk+(nr+ℓk)≡anr+(nr+ℓk)≡r+md+ℓk(modc)(∗∗)
But, when k varies, ℓk(modc) goes through all multiples of d. Thus there exists k such that ℓk≡(q−m)d(modc). Plugging it in (∗∗),
anr+ℓk+(nr+ℓk)≡r+md+(q−m)d(modc)⟺anr+ℓk+(nr+ℓk)≡r+qd≡b(modc)
Hence, we can take x=nr+ℓk and the induction step is complete.