Solution 1. Clearly, a>1. We consider three cases.
Case 1: We have a<p. Then we either have a⩽b which implies a∣ap−b!=p leading to a contradiction, or a>b which is also impossible since in this case we have b!⩽a!<ap−p, where the last inequality is true for any p>a>1.
Case 2: We have a>p. In this case b!=ap−p>pp−p⩾p! so b>p which means that ap=b!+p is divisible by p. Hence, a is divisible by p and b!=ap−p is not divisible by p2. This means that b<2p. If a<p2 then a/p<p divides both ap and b! and hence it also divides p=ap−b! which is impossible. On the other hand, the case a⩾p2 is also impossible since then ap⩾(p2)p>(2p−1)!+p⩾b!+p.
Comment. The inequality p2p>(2p−1)!+p can be shown e.g. by using
(2p−1)!=[1⋅(2p−1)]⋅[2⋅(2p−2)]⋯[(p−1)(p+1)]⋅p<((22p)2)p−1⋅p=p2p−1
where the inequality comes from applying AM-GM to each of the terms in square brackets.
Case 3: We have a=p. In this case b!=pp−p. One can check that the values p=2,3 lead to the claimed solutions and p=5 does not lead to a solution. So we now assume that p⩾7. We have b!=pp−p>p! and so b⩾p+1 which implies that
v2((p+1)!)⩽v2(b!)=v2(pp−1−1)=LTE2v2(p−1)+v2(p+1)−1=v2(2p−1⋅(p−1)⋅(p+1)),
where in the middle we used lifting-the-exponent lemma. On the RHS we have three factors of (p+1)!. But, due to p+1⩾8, there are at least 4 even numbers among 1,2,…,p+1, so this case is not possible.
Solution 2. The cases a=p are covered as in solution 1, as are p=2,3. For p⩾5 we have b!=p(pp−1−1). By Zsigmondy's Theorem there exists some prime q that divides pp−1−1 but does not divide pk−1 for k<p−1. It follows that ordq(p)=p−1, and hence q≡1mod(p−1). Note that p=q. But then we must have q⩾2p−1, giving
b!⩾(2p−1)!=[1⋅(2p−1)]⋅[2⋅(2p−2)]⋯[(p−1)⋅(p+1)]⋅p>(2p−1)p−1p>pp>pp−p,
a contradiction.
Solution 3. The cases a=p are covered as in solution 1, as are p=2,3. Also b>p, as pp>p!+p for p>2. The cases p=5,7,11 are also checked manually, so assume p⩾13. Let q∣p+1 be an odd prime. By LTE
vq(pp−p)=vq((p2)2p−1−1)=vq(p2−1)+vq(2p−1)=vq(p+1)
But b⩾p+1, so then vq(b!)>vq(p+1), since q<p+1, a contradiction. This means that p+1 has no odd prime divisor, i.e. p+1=2k for some k.
Now let q∣p−1 be an odd prime. By LTE
vq(pp−p)=2vq(p−1)
Let d=vq(p−1). Then p⩾1+qd, so
vq(b!)⩾vq(p!)⩾vq(qd!)>qd−1⩾2d
provided d⩾2 and q>3, or d⩾3.
If q=3,d=2 and p⩾13 then vq(b!)⩾vq(p!)⩾vq(13!)=5>2d. Either way, d⩽1.
If p>2q+1 (so p>3q, as q∣p−1) then
vq(b!)⩾vq((3q)!)=3
so we must have q⩾2p, in other words, p−1=2q. This implies that p=2k−1 and q=2k−1−1 are both prime, but it is not possible to have two consecutive Mersenne primes.
Solution 4. Let a=p,b>p and p⩾5 (the remaining cases are dealt with as in solution 3). Modulo (p+1)2 it holds that
pp−p=(p+1−1)p−p≡(1p)(p+1)(−1)p−1+(−1)p−p=p(p+1)−1−p=p2−1≡0(mod(p+1)2)
Since p⩾5, the numbers 2 and 2p+1 are distinct and less than or equal to p. Therefore, p+1∣p!, and so (p+1)2∣(p+1)!.
But b⩾p+1, so b!≡0≡pp−p(mod(p+1)2), a contradiction.
Therefore, the only solutions are (2,2,2) and (3,4,3).