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}$.
 A: 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).
A: We prove that $a = 1009, b = 1$ is the only solution.
First we restrict attention to the case in which $a, b \geq 3$.
We can rewrite the equation as
$$\frac{\log a}{a} - \frac{\log b}{b} = \frac{\log\left(1 + \frac{1008}{b^a}\right)}{ab}.$$
Let $f(x) = \frac{\log x}{x}$. We have $f'(x) = \frac{1 - \log x}{x^2} < 0$, so $f(x)$ is decreasing on $[3,+\infty)$. Therefore we have $b > a$.
By the mean value theorem, there is some $c \in (a,b)$ such that
$$\frac{\log a}{a} - \frac{\log b}{b} = (b - a)\frac{\log c - 1}{c^2} \geq \frac{\log 3 - 1}{b^2}.$$
On the other hand, we have 
$$\frac{\log\left(1 + \frac{1008}{b^a}\right)}{ab} \leq \frac{1008/b^a}{ab} = \frac{1008}{ab^{a+1}}.$$
Therefore 
$$ab^{a-1} \leq \frac{1008}{\log 3 - 1} < 10222.$$
Consequently, we must have $a \leq 5$, and:


*

*If $a = 3$, then $4 \leq b \leq 58$.

*If $a = 4$, then $5 \leq b \leq 13$

*If $a = 5$, then $b = 6$.


But all of these cases are impossible.


*

*$5^6 - 6^5 \ne 1008$, so $a \ne 5$.

*When $a = 4$, we have $4^b - b^4 = 1008$. $1008$ is equal to $16$ modulo $32$, so we must have $b = 2$ modulo 4. But $b = 6$ and $b = 10$ are not solutions.

*When $a = 3$, we have $3^b - b^3 = 1008$. Since $b > 3$, we have $b^3 = 18$ modulo 27, but this equation has no solutions.
Other cases
When $b = 1$, we have only the solution $a = 1009$.
When $b = 2$, we have $a^2 > 2^a + 1$, which never occurs.
When $a = 1$, there are obviously no solutions.
When $a = 2$, we have $2^b - b^2 = 1008$. If $x_n = 2^n - n^2$, then $x_{n + 1} - x_n = 2^n - (2n + 1) > 0$ for $n \geq 3$, so the sequence $x_n$ is increasing from $n \geq 3$. We have $x_{10} < 1008 < x_{11}$, so there are no solutions for $a = 2$.
A: 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}$.
