Solution (source code)

= Solution

If $p\mid a$, there is nothing to prove. Otherwise the only possible positive common divisors of the <prime> $p$ and $a$ show that $\gcd(p,a)=1$. By <Bézout's identity>, $up+va=1$ for some <integers> $u,v$. Multiplying by $b$ gives $b=upb+vab$. Both terms on the right are divisible by $p$, the second because $p\mid ab$. Hence \b[$p\mid b$]. This proves <Euclid's lemma>, including when either factor is zero or negative.