pub trait ModInverse<M = Self> {
type Output;
// Required method
fn mod_inverse(self, m: M) -> Option<Self::Output>;
}Expand description
Finds the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
Required Associated Types§
Required Methods§
fn mod_inverse(self, m: M) -> Option<Self::Output>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl ModInverse for u8
impl ModInverse for u8
Source§fn mod_inverse(self, m: u8) -> Option<u8>
fn mod_inverse(self, m: u8) -> Option<u8>
Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
Returns None if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), m.significant_bits()).
§Panics
Panics if self is greater than or equal to m.
§Examples
See here.
type Output = u8
Source§impl ModInverse for u16
impl ModInverse for u16
Source§fn mod_inverse(self, m: u16) -> Option<u16>
fn mod_inverse(self, m: u16) -> Option<u16>
Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
Returns None if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), m.significant_bits()).
§Panics
Panics if self is greater than or equal to m.
§Examples
See here.
type Output = u16
Source§impl ModInverse for u32
impl ModInverse for u32
Source§fn mod_inverse(self, m: u32) -> Option<u32>
fn mod_inverse(self, m: u32) -> Option<u32>
Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
Returns None if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), m.significant_bits()).
§Panics
Panics if self is greater than or equal to m.
§Examples
See here.
type Output = u32
Source§impl ModInverse for u64
impl ModInverse for u64
Source§fn mod_inverse(self, m: u64) -> Option<u64>
fn mod_inverse(self, m: u64) -> Option<u64>
Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
Returns None if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), m.significant_bits()).
§Panics
Panics if self is greater than or equal to m.
§Examples
See here.
type Output = u64
Source§impl ModInverse for u128
impl ModInverse for u128
Source§fn mod_inverse(self, m: u128) -> Option<u128>
fn mod_inverse(self, m: u128) -> Option<u128>
Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
Returns None if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), m.significant_bits()).
§Panics
Panics if self is greater than or equal to m.
§Examples
See here.
type Output = u128
Source§impl ModInverse for usize
impl ModInverse for usize
Source§fn mod_inverse(self, m: usize) -> Option<usize>
fn mod_inverse(self, m: usize) -> Option<usize>
Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
Returns None if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), m.significant_bits()).
§Panics
Panics if self is greater than or equal to m.
§Examples
See here.