= Counting terms of an arithmetic progression
{title2=$n=1+(a_n-a_1)/d$}
Starting at $a_1$ and repeatedly adding a nonzero <common difference> $d$, a proposed final value $z$ is reached at position
$$
n=1+\frac{z-a_1}{d}
$$
if and only if this expression is a positive <integer>. For $a_1=7$, $d=3$, and $z=28$, it gives $n=8$. The quotient $21/3=7$ counts increments, while the initial entry adds one to the number of <sequence terms>. The proposed value $27$ gives $n=1+20/3$, which is not an <integer>, so it is never reached by these updates. The test also handles decreasing <arithmetic progressions>; when $d=0$, the repeated value alone cannot determine a length.
Back to article page