5. Let the arithmetic sequence $a_{1}, a_{2}, \ldots, a_{n}$ have a common difference not equal to 0, and $a_{3}, a_{4}, a_{7}, a_{n}$ form a geometric sequence, then the number of terms in this sequence is $\qquad$
5. 16

Analysis: Let the first term of the arithmetic sequence be $a_{1}$, and the common difference be $d$, then $\left(a_{1}+2 d\right)\left(a_{1}+6 d\right)=\left(a_{1}+3 d\right)^{2}$, which gives $a_{1}=-\frac{3}{2} d$, so the general term formula is $a_{n}=a_{1}+(n-1) d=\left(n-\frac{5}{2}\right) d$. And $a_{3}=\frac{1}{2} d, a_{4}=\frac{3}{2} d, a_{7}=\frac{9}{2} d$, so $a_{n}=\frac{27}{2} d$, therefore $n=16$.