Solution (source code)

= Solution

Because the primes are distinct, <Fermat's little theorem> gives $q^{p-1}\equiv1\pmod p$ and $p^{q-1}\equiv1\pmod q$. The other term in each modulus vanishes. Therefore
$$
p^{q-1}+q^{p-1}-1\equiv0\pmod p,\qquad
p^{q-1}+q^{p-1}-1\equiv0\pmod q.
$$
The distinct primes are <coprime>, so their product divides this <integer>. Hence
$$
\boxed{p^{q-1}+q^{p-1}\equiv1\pmod{pq}}.
$$