Function utils::number::mod_inverse

source ·
pub fn mod_inverse<T: SignedInteger>(a: T, b: T) -> Option<T>
Expand description

Computes the modular inverse of a modulo b if it exists.

§Examples

assert_eq!(mod_inverse(3, 5), Some(2));
assert_eq!((3 * 2) % 5, 1);

assert_eq!(mod_inverse(10, 23), Some(7));
assert_eq!((10 * 7) % 23, 1);

assert_eq!(mod_inverse(2, 8), None);