Check that an inverse exists
Use coprimality before extended Euclid or the prime-modulus shortcut.
Understand the idea
An inverse x satisfies ax congruent to 1 modulo m. For m ≥ 2 it exists exactly when gcd(a,m) = 1. Extended Euclid finds coefficients ax + my = gcd(a,m); when this is 1, normalize x to obtain the inverse.
Trace a small example
The inverse of 3 modulo 10 is 7 since 21 has residue 1. The value 2 has no inverse modulo 10. For prime p and a not divisible by p, Fermat gives inverse(a) = a^(p − 2) modulo p.
Conditions and cost
The Fermat shortcut does not apply to arbitrary composite moduli or to zero modulo p. Modular a/b means a × inverse(b), with explicit failure if b is not invertible. Bound coefficient-update arithmetic in extended Euclid.
Does 6 have an inverse modulo 15?
Turn the idea into code
Compute 4/3 modulo 7.
Give me a hint
The inverse of 3 modulo 7 is 5.
Show the explained solution
4 × 5 mod 7 = 6. Ordinary integer 4/3 would give an unrelated answer.
Your notes
Mark complete when you can explain it yourself.