For a moment, assume a2=a4. Through the following solution, we shall several times use the fact that 2n<an<2n. We divide the solution into three parts;
i. Large primes part; We prove that for each prime p≥5 the only prime less than or equal to p that divides ap,ap2,… is p;
ii. We shall prove apk=pk for all primes p≥5;
iii. Small primes part; We resolve the problem for p=2,p=3 and conclude the proof.
In order to prove part one; for each prime p, we define sets of primes Ap,Bp as follows;
Ap={q≤p:q∣apk,k=1,2,…},
Bp={q:q∣apk,k=1,…}
That is, Ap=Bp∩[1,p]. We shall firstly prove Ap's as well as Bp's are disjoint. Notice that for prime p=q we have gcd(apk,aql)=1. Hence, Bp's are disjoint. Analogously, Ap's are disjoint. We shall then prove that Ap is non-empty for p≥5. Assume to the contrary that Ap is empty for some p≥5. Notice that apk+1=apk since apk<2pk<21pk+1<apk+1. Moreover, apk divides apk+1 since otherwise, there is at least one prime q>p such that vq(apk)>vq(apk+1). Hence, gcd(apk+1,apk)≤qapk<papk.
On the other hand,
gcd(pk,pk+1)gcd(apk+1,apk)<pk+1apk<p2<21.
A contradiction. Thus, apk∤apk+1. Hence, for each n≥1 there would be a prime number qn>p that qn∤apn−1apn. Hence,
apn≥q1⋯qn>(p+1)n.
Choose n suitably large to ensure that (p+1)n>2pn, we are done. Thus, Ap is not empty for p≥5. Now, for each N; ⋃p<NAp⊂{p∈P,p<N}, where P is the set of prime numbers.
Then, A2∪A3∪A5⊂{2,3,5}. Notice that A2,A3,A5 are disjoint. Further, since a2∈{2,3},a3∈{2,3,4,5} we find that if a2=2 then A2 is empty and hence—and as you would see in the small primes part—we can prove that a3∈{2,4} hence, A3 has one element. Since gcd(a5,a3)=gcd(a5,a2)=1 we find that A5={5} and for all p≥5, Ap and {2,3,5} are disjoint.
We are ready to prove the part ii. Now, comparing the sizes, we find that ∣Ap∣=1 and ⋃p<NAp={p∈P,p<N}, for each N. Hence, Ap={p} for all p≥5. Now, if there is a q=p in Bp then q would not be a member of Bq and hence Aq which is a contradiction. Yielding Bp={p} and hence apk=pk for all p≥5.
For the small prime part. We shall firstly prove a3=5, indeed, If a3=5 it follows that 1<gcd(a6,a2)<4. Hence, 3∣a6. By the same reasoning, 23<gcd(a6,a3)<6 hence, 5∣a6. It follows that a6≥15, a contradiction.
Now, since a1=1 and a2∈{2,3}. If a2=3 then a3∈{2,4}. Hence, a3=5. If a3∈{2,4} then a6 must be divisible by 6 and a6<12 yielding a6=6. On the other hand, a4=3. A contradiction. Hence, a2=2. Now, we shall prove that a3=3. Indeed, if a3=5 since a5=5, we yield a contradiction. Finally, notice that apk=pk∣ampk. Hence, n∣an and then an=n.
It is now time to remove banal condition a2=a4 in the following way. Indeed, if a2=3 and a3∈{2,4} it follows that (a2n), (a3n) would be powers of 3 and 2, respectively. Let N=2a3bT, gcd(T,6)=1. Then, we can prove that aT=T and hence, from 21T<gcd(T,aN)<2T we find that T∣aN.
Let (v2(aN),v3(aN))=(c,d). It follows that 21<gcd(N,2C)gcd(aN,a2C)<2. Choose C large enough such that C>a and v3(a2C)>d it follows that 2a−1<3d<2a+1. Analogously, choosing D>b, v2(a3D)>c yields 23b<2c<2⋅3b. It is now clear that if a=1 then d=1. If 2c>34⋅3b then aN≥3⋅34⋅3b⋅T=2N, a contradiction. Hence, 2c≤34⋅3b.
Since the sequence {(n⋅log23)} is dense on (0,1), for all ε>0 there is an integer d such that {d⋅log23}∈(1+log232,1+log2(ε+32)). Then, 32⋅2a1<3d<(32+ε)2a1, for some a1. Let N=2a1⋅3b⋅T now, by choosing ε small enough, it follows that v3(aN)=d. Now, if 2v2(aN)<4+ε33b, for some ε>0 it follows that aN<4+ε33b⋅(32+ε)2a1⋅T, it follows that aN<2N. A contradiction. Hence, we find that 4+ε33b≤2v2(aN)≤34⋅3b.
Now, choose c such that {c⋅log32}∈(1+log332,1+log34+ε3), it follows that 32⋅3b1<2c<4+ε3⋅3b1. Choosing N=2a13b1T, it follows that v2(aN)∈{c,c+1}. On the other hand, from
4+ε33b1≤2v2(aN)≤34⋅3b1
We find that v2(aN)=c+1. But then 2c=22v2(aN)>32⋅3b1. Yielding 2v2(aN)>34⋅3b1, a contradiction.
Finally, We now rule out the case a3=5. Suppose a3=5. As gcd(a3k,a3)>1, the a3k are all divisible by 5. By the preceding, p∣ap for all primes p=3; as gcd(a3k,ap)=1 for these primes, the a3k are all powers of 5; say, a3k=5mk. By Kronecker's density theorem, as n runs through the positive integers, the fractional parts {nlog35} form a dense set in (0,1). Hence log32<{nlog35}<log325 for some n. Let k=⌊nlog35⌋ and carry out obvious calculations to get 5n−1<21⋅3k and 2⋅3k<5n. As 21⋅3k<a3k<2⋅3k, it follows that 5n−1<21⋅3k<5mk<2⋅3k<5n, so n−1<mk<n. This contradiction implies a3=3 and A3=B3={3}, as desired.
Finally, by the preceding, A5={5}, as it is non-empty and disjoint from both A2 and A3. Now, a5<10 forces a5=5, so B5={5}.