Prove that $a \equiv b \pmod{1008}$ Suppose that the positive integers $a$ and $b$ satisfy the equation $$a^b-b^a = 1008.$$ Prove that $a \equiv b \pmod{1008}$.


Taking the equation modulo $1008$ we get $a^b \equiv b^a \pmod{1008}$, but I didn't see how to use this to get that $a \equiv b \pmod{1008}$.
Suppose
$a^b-b^a = n$
with all variables
positive integers.
If $n=1$,
this is Catalan's problem
for which the only solution is
$a=3, b=2$.
Assume
$n \ge 2$.

I will show that there
at most a finite number of solutions
and give bounds for
$a$ and $b$
in terms of $n$.

For $n=1008$,
the only solution is
$a=n+1, b=1$.

If $b=1$,
then
$a-1 = n$,
so $a = n+1$.
Then 
$a-b = n
\equiv 0 \bmod n$.

If $b=2$,
then
$a^2-2^a = n$.
Since
$a^2 \le 2^a$
for 
$a\le 2$
and
$a \ge 4$,
we must have
$a=3$
so the only $n$ that works
is
$n =3^2-2^3 = 1$.

If
$b \ge 3$,
if
$a &gt; b$
then
$b^a &gt; a^b$
(since
$b^{1/b} &gt; a^{1/a}$
)
so no solution.
Therefore
if $b \ge 3$
then $a &lt; b$.

We can't have $a=1$.

If $a=2$
then
$2^b-b^2 = n$.
Since the left side
is increasing for
$b \ge 4$,
there is at most one solution.
For $n=1008$,
there is no solution.

If $a=3$
then
$3^b-b^3 = n$.
Since the left side
is increasing for
$b \ge 3$,
there is at most one solution.
For $n=1008$,
there is no solution.

Suppose 
$a \ge 4$
so $b \ge 5$.

Let $b = a+c$
where $c \ge 1$.
Then,
since
$(1+1/x)^x &lt; e$
and
$u^r - v^r
\ge (u-v)v^{r-1}
$
if
$u &gt; v &gt; 1$
and
$r &gt; 1$,

$\begin{array}\\
n
&amp;=a^{a+c}-(a+c)^a\\
&amp;=a^a(a^{c}-(1+c/a)^a)\\
&amp;\gt a^a(a^{c}-e^c)\\
&amp;\gt a^a(a^{c}-(a-2)^c)\\
&amp;\gt 2a^ac(a-2)^{c-1}\\
&amp;\ge 2a^a\\
\end{array}
$

This gives a 
finite number of
possible values for $a$.

If
$n=1008$,
the only possibility is
$a=4$
(since
$4^4 = 256$
and
$5^5 = 3125$).
If $a=4$,
this is
$n
\gt 2\cdot 256c2^{c-1}
\ge 512c
$
so the only possibility is
$c=1$
so $b= 5$.

This does not work
(to see without computation:
$4^5-5^4$ is odd).
We have $1008 = 2^4 \cdot 3^2 \cdot 7$. First note that $a \equiv b \pmod{2}$ since $1008$ is even. Note that $2 \nmid a,b$ since if $2 \mid a,b$ then $a,b \leq 5$. Therefore, $a^b \equiv a \pmod{8}$ and $b^a \equiv b \pmod{8}$, so $a \equiv b \pmod{8}$. Then since $a^4 \equiv 1 \pmod{16}$, we have $a^b \equiv a^a \pmod{16}$ and so $a^a \equiv b^a \pmod{16}$. If $a \equiv 1 \pmod{4}$, then $a \equiv b \pmod{16}$. If $a \equiv 3 \pmod{4}$, then $a^3 \equiv b^3 \pmod{16}$ gives $a \equiv b \pmod{16}$.

We have $a^b \equiv a \pmod{3}$ and $b^a \equiv b \pmod{3}$ since $a$ and $b$ are both odd. Thus $a \equiv b \pmod{3}$. If $a \equiv b \equiv 1 \pmod{6}$, then $a^b \equiv a \pmod{9}$ and $b^a \equiv b \pmod{9}$ by Euler's Totient Theorem since $\varphi(9) = 6$. Thus $a \equiv b \pmod{9}$ in this case. If $a \equiv b \equiv 5 \pmod{6}$, then $a^b \equiv a^5 \pmod{9}$ and $a^5 \equiv b^5 \pmod{9}$. Thus $a \equiv b \pmod{9}$.

Similarly since $\varphi(7) = 6$ we get taking the cases $a \equiv b \equiv 1 \pmod{6}$ and $a \equiv b \equiv 5 \pmod{6}$ again that $a \equiv b \pmod{7}$.