TITLE: Prove that $a \equiv b \pmod{1008}$
QUESTION [5 upvotes]: 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}$.

REPLY [3 votes]: 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 > b$
then
$b^a > a^b$
(since
$b^{1/b} > a^{1/a}$
)
so no solution.
Therefore
if $b \ge 3$
then $a < 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 < e$
and
$u^r - v^r
\ge (u-v)v^{r-1}
$
if
$u > v > 1$
and
$r > 1$,
$\begin{array}\\
n
&=a^{a+c}-(a+c)^a\\
&=a^a(a^{c}-(1+c/a)^a)\\
&\gt a^a(a^{c}-e^c)\\
&\gt a^a(a^{c}-(a-2)^c)\\
&\gt 2a^ac(a-2)^{c-1}\\
&\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).