Let $t$ be the amount of time, in hours, that B has travelled when B catches up to A.
Note that A has travelled a distance $(2+t)(4)=8+4t$.
In $3$ hours B has travelled $1+2+4$, not enough.
In $4$ hours B has travelled $1+2+4+8$, and A has travelled $24$, so B is still behind.
In $5$ hours B has travelled $1+2+4+8+16$, and A has travelled $28$, so B is ahead.
Thus it took more than $4$ hours but less than $5$.
During that time, B travelled $1+2+4+8 +16(t-4)$. Now solve the linear equation
$$8+4t=1+2+4+8+16(t-4).$$
Remark: With other much larger numbers, finding the greatest integer in the number of hours travelled by B could be unpleasant.
Added: TonyK in a comment interprets $1$, $2$, and so on as meaning $1,2,3,4,\dots$. This is perfectly reasonable, physically more reasonable than repeated doubling. Let $n$ be the greatest integer $\le t$. In time $2+n$, A has travelled $8+4n$ and B has travelled $1+2+3+\cdots +n=\frac{n(n+1)}{2}$. We want
$$\frac{n(n+1)}{2}\le 8+4n \lt \frac{(n+1)(n+2)}{2}.$$
Finding the right $n$ can be done by trial and error, but for this interpretation it can also be done algebraically. It turns out that $n=8$. Calculating as in the main answer, we find that in $8$ hours B has travelled a distance $36$, so we get
$$8+4t=36+(t-8)(9).$$