Ahmed and Beth have respectively $p$ and $q$ marbles, with $p > q$. Starting with Ahmed, each in turn gives to the other as many marbles as the other already possesses. It is found that after $2n$ such transfers, Ahmed has $q$ marbles and Beth has $p$ marbles. Find $\frac{p}{q}$ in terms of $n$.
The number of marbles each person has seems to follow a pattern, for example: Ahmed initially has $p$ marbles then $p-q$ and then $2p-2q$, with the coefficient of $p$ initially $1$ and the coefficient of $q$ initially $0$, they follow the pattern that $a_{m+1}=2a_{m}$ if $m$ is odd and $a_{m+1}=2a_{m}-1$ if $m$ is even (where $m$ is the number of exchanges), a similar result is true for Beth. I though if I could find a formula for $a_{m}$ in terms of $n$ the I could set it equal to $q$ in Ahmed's case and find $\frac{p}{q}$ in terms of $n$, but I can't find of way of doing this. I've also considered trig substitution, but I don't really know what to substitute.
If anyone could come up with an answer, that would be greatly appreciated.
You already have a good answer, this is just another way to solve the recurrence. Let $p+q = S$ and denote $a(n)$ the marbles Ahmed has. Clearly $a(0) = p$.
So let $a(2k)$ denote the marbles Ahmed has after $2k$ transfers. Then Beth must have $S-a(2k)$ marbles by the Law of Conservation of Marbles. next transfer must then lead to $a(2k+1) = a(2k)-(S-a(2k))= 2a(2k)-S$, and after that we have $a(2k+2) = 4a(2k)-2S$.
We may now define $f(k) = a(2k)$ to simplify things, and get the recursion $$f(k+1) = 4f(k)-2S$$
with $f(0)=p$. Solving this would give $$f(k) = \frac13\left((4^k+2)p-2(4^k-1)q \right)$$
Setting $f(n)=q$, we have $3q = (4^k+2)p-2(4k-1)q \implies \dfrac{p}q = \dfrac{2\cdot4^n+1}{4^n+2}$...