TITLE: When does $(a,b) \to (2a, b-a)$ terminate? ($a \leq b$)
QUESTION [5 upvotes]: I've got a following problem. 
Let's have two integers $a$ and $b$, assume $a \leq b$ (if not, we swap them)
Algorithm is just one step, produce new numbers: $2a$ and $b-a$ 
Algorithm stops when $a = b$, otherwise it gonna cycle infinitely. 
So far, i got that for any integers $a$ and $b$ algorithm gonna stop $\leftrightarrow$  $\frac{b}{a} = 2^n - 1$ or $\frac{b}{a}=(2^n + 1)/(2^n - 1)$ or $\frac{b}{a}=(2 ^ {n+1} + 2 ^ n - 1)/(2 ^ n + 1)$
But i can't come up with anything simplier. I'd really love to see some hints or solutions to this! Thanks in advance

REPLY [2 votes]: Interesting problem.
I assumed $a \gt 0$.
I believe the following works:
Let $$\frac{a}{b} = \frac{p}{q}$$
where $\text{gcd}(p,q) = 1$ and $p, q \gt 0$
Then the algorithm terminates iff $$p+q = 2^m$$ where $m$ is an integer $\ge 1$
Proof:
It is enough to consider $\text{gcd}(a,b) = 1$ (i.e. $p = a, q = b$).
Also notice that each step of the algorithm keeps $a+b$ the same. So assume $a,b$ are both odd (if their sum was odd, then we can never get two equal numbers).
Also note that the algorithm terminates for $(a,b)$ iff it terminates for $(ca, cb)$ where $c \neq 0$
Now we can map $(a,b)$ to $\left(a, \frac{b-a}{2}\right)$ by dividing out a $2$.
Notice that $\text{gcd}\left(a, \frac{b-a}{2}\right) = 1$
Thus we can either keep dividing out a $2$ after each step and ultimately end up with $(1,1)$ (because $\text{gcd}$ remains $1$) or hit a point when the sum becomes odd (we no longer can divide out a $2$), and we have to enter a cycle. The former corresponds to $a+b = 2^m$, and the latter corresponds to $a+b = 2^{n}(2k+1)$.