Modular inverse by Fermat, by hand
pow_mod(a, P - 2, P): Mod<P> (std.mod) and Z(a).inv()
const P = 998244353
let a = 3
print(a * pow_mod(a, P - 2, P) % P)type Z = Mod<998244353>
let a = Z(3)
print(a * a.inv())Why
pow_mod(a, P - 2, P) is Fermat's little theorem written out: the inverse of a modulo a prime P. It is right only when P is prime and a is not a multiple of P, and every product around it still needs its own % P. type Z = Mod<P> (std.mod) computes in the residues: Z(a).inv() is the inverse, it traps when a has none, and *, + and - reduce on their own.
The practice it serves
A hand-written pattern the language or the standard library already says in one step. Family: S.mod: modular arithmetic and combinatorics.
Not flagged
A near miss: close to the pattern, but not it.
const P = 998244353
print(pow_mod(3, P - 1, P), pow_mod(2, 10, P))Turn it off
For one block, wrap it in with lint(fermat_inverse: allow):. For a project, add fermat_inverse = "allow" under [lints] in cp.toml.
Generated from spec/lints/fermat_inverse, the same record the linter is built from.