Fix point of squaring numbers mod p
Let us factor $p-1=2^am$, where $m$ is odd. The size of your terminal set is $m$. You are working with a cyclic group of order $p-1$. As $m$ is odd, the Chinese Remainder Theorem tells you that there is an isomorphism $$ \mathbb{Z}_p^*\cong C_m\times C_{2^a}. $$ Repeated squaring kills the $C_{2^a}$ after $a$ iterations, and squaring is bijective on $C_m$.
If you include $0$ (I didn't), then add one.