In my computer science class I had to solve the following problem from Codeforces: https://codeforces.com/problemset/problem/55/A It's about some pillows placed on a circle and a fly that jumps over $n$ pillows, where $n = \overline{0,k}$. The fly does this for an infinite amount of time. Will the fly reach all the pillows for a certain number of pillows $z$?
By playing around I had discovered that the fly can reach all pillows when the initial number of pillows $z$ is a power of 2 and the program was solved, but I want to prove it mathematically. I managed to describe the movements of the fly by the following sequence: $a_n = (a_{n-1} + n)mod\ z, a_0 = 1;$ Doing some internet research I found out that I can write $a_n = (a_{n-1} + n)$ as this explicit function $\frac{n(n+1)}{2} + 1$. This is where I am stuck. Is there any method to prove this in a digestible way(for a 1st year Computer Science student)?