Understand a Solution of $3^{p}=1+2^{q}$ I'm going to understand this solution from a book : 
Determine all natural numbers $p,q$ such that : 

$$3^{p}=1+2^{q}$$ 

Solution is : 
First we note that : 
$(p,q)\in{(1,1),(2,3)}$
We will prove that this is all solutions : 
We know that : 
$3^{2k}\equiv 1 \pmod{4}$ 
And 
$3^{2k+1}\equiv 3\pmod{4}$ 
So : if $p=2k$ then 
$2^{q}=3^{2k}-1=(3^{k}-1)(3^{k}+1)\implies^{why ?} 3^{k}-1=2\implies k=1\implies m=3$ 
If $p=2k+1$ then $2^{q}=3^{2k+1}-1\equiv 2\pmod{4}\implies q=1\implies p=1$
So  $(p,q)\in{(1,1),(2,3)}$
This is solution from a book but I don't understand why he chose mod $4$ and why
This implies  $2^{q}=(3^{k}-1)(3^{k}+1)\implies 3^{k}-1=2$ ???
 A: The problem is a typical number theory problem involving powers and prime numbers.
Hence, before rushing to the solution, we will try to develop a proper insight on how to tackle such problems. You can skip to the block quotes for quick answers to your question. However, I would suggest a thorough view of the insight.
Insight:
One can see that the problem involves the prime numbers $2$ and $3$. A common technique used by experienced problem solvers would be to somehow factorize the expression and use divisibility lemmas and then arrive at the conclusion.
Now in our equation, we have,
$3^p = 1 + 2^q$
So, how could we manipulate the equation so that we get a fruitful result? Since the equation involves exponents, it would rather be useful to work in ($mod$ $x$).
Now, a common question would be : In which ($mod$ $x$) should I work? Using numbers which upon dividing $3^p$ or $2^q$  leave remainders such as $1$,$-1$, $0$ are the best to work with.
Let us first start with ($mod$ $2$): $3\equiv 1\pmod 2 \Rightarrow 3^p\equiv 1\pmod 2$. We see that this doesn't take us any further in solving the problem. (Since, we would get $1\equiv 1\pmod 2$, which is always true.)
Let us now try ($mod$ $3$): $2\equiv -1\pmod 3 \Rightarrow 2^q\equiv (-1)^q\pmod 3$. Hence, from the equation we have $3^p \equiv 0 \equiv 1 + 2^q \equiv 1 + (-1)^q\pmod 3$. From this we have that $q$ is odd. This, even though might seem helpful at the start, will not help in any factorization or application of divisibility lemmas. Let us keep this result aside and move on.
Let us now try working in ($mod$ $4$): $3\equiv -1\pmod 4 \Rightarrow 3^p\equiv (-1)^p\pmod 4$. Therefore from the equation we get,
$3^p \equiv (-1)^p \equiv 1 + 2^q\pmod 4$.
From this, for any $q \geq 2$ we have $p$ to be even. Let $p = 2k$,
then, $2^q = 3^{2k} - 1 = (3^{k} - 1)(3^{k} + 1)$

Note that $2$ is a prime number. Hence, you can factorize $2^q$ only
into powers of $2$. This is because no other number other than powers
of $2$ can divide $2^q$. A first glance, this statement might bring
about confusion. But do read the above given statement sufficient
number of times and analyze it properly to get the intuition.

From here, you can argue in 2 different ways,


*

*Since both $(3^{k} - 1)$ and $(3^{k} + 1)$ are powers of $2$ and they differ by $2$, the only possibility is that they are $2$ and $4$.
Obviously, since the smaller one among them should be $(3^{k} - 1)$,
we have $(3^{k} - 1) = 2$

*Since the smaller power of 2 among them should be $(3^{k} - 1)$, we should have $(3^{k} - 1) | (3^{k} + 1) \Rightarrow (3^{k} - 1) | (3^{k} + 1) - (3^{k} - 1) \Rightarrow (3^{k} - 1) | 2$.  Thus, since
$(3^{k} - 1)$ is a power of $2$, it can either be equal to $2^0$ or
$2^1$. We can eliminate the case of $2^0$ since , $3^k \neq 2$. Hence,
the result.


You can use any one of the above 2 arguments. However, the second one would be stronger in certain other cases. For this problem, the first argument is sufficient.
Notice that we took $q \geq 2$, for $q \lt 2$, we have a trivial solution (1, 1).
A: Note  that "mod 4" was not employed in the case $p=2k$. For the case $3\le p=2k+1,$ observe that $3^{2k+1}-1=(3-1)S(k)=2S(k)$ where $S(k)=\sum_{j=0}^{2k}3^j$ is a sum of $2k+1$ odd natural numbers. So if $k\ge 1$ then $S(k)$ is odd and greater than $1,$ so $S(k)$ cannot be a divisor of any $2^q.$
