Consider powers of 10 written as binary numbers.
10 = 1010 , 100 = 1100100 , 1000 = 1111101000
How can I find a formula for the number of zeroes between the last and the second last 1?
Consider powers of 10 written as binary numbers.
10 = 1010 , 100 = 1100100 , 1000 = 1111101000
How can I find a formula for the number of zeroes between the last and the second last 1?
As described in the comments: the answer, let's call it $f(n)$, is one less than the greatest power of $2$ which divides $5^n-1$. Thus $$f(n)=v_2(5^n-1)-1$$ where, as usual, $v_2(k)$ denotes the greatest power of $2$ dividing $k$.
To compute $v_2(5^n-1)$...
first note that this is $2$ if $n$ is odd: indeed $5^n-1=(5-1)(5^{n-1}+\dots+1)$ regardless of the parity of $n$ and, if $n$ is odd the second factor is easily seen to be odd.
If $n=2k$ is even then $$5^n-1=5^{2k}-1=(5^k-1)(5^k+1)$$ Now, the second factor here is even (clearly) but is never divisible by $4$ (as $5^k=1$ mod($4$)). It follows that $$v_2(5^{2k}-1)=v_2(5^k-1)+1$$
Combining these remarks one sees that, for $n=2^km$ with $m$ odd we have $$v_2(5^{2^km}-1)=2+k$$
thus, the final answer is $$f(n)=f(2^km)=k+1$$
This is the number of trailing zeroes at the end of $5^p/2$ (integer division). In mathematical terms, it is the multiplicity of the factor $2$ in the prime decomposition of this number.
In programming, you will shift right until you get an odd number, and count the shifts.