pub trait ModDivList<RHS = Self, M = Self> {
type Output;
// Required method
fn mod_div_list(
self,
other: RHS,
m: M,
) -> Option<(Self::Output, Self::Output, Self::Output)>;
}Expand description
Finds all quotients of a number and another number modulo a third number $m$, returning None
if no quotient exists. The inputs must be already reduced modulo $m$.
The quotients form an arithmetic progression: Some((start, stride, length)) means that the
quotients are exactly the numbers $\text{start} + \text{stride} \cdot i$ for $0 \leq i <
\text{length}$, where start is the smallest quotient.
Required Associated Types§
Required Methods§
fn mod_div_list( self, other: RHS, m: M, ) -> Option<(Self::Output, Self::Output, 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 ModDivList for u8
impl ModDivList for u8
Source§fn mod_div_list(self, other: u8, m: u8) -> Option<(u8, u8, u8)>
fn mod_div_list(self, other: u8, m: u8) -> Option<(u8, u8, u8)>
Finds all quotients of a number and another number modulo a third number $m$,
returning None if no quotient exists. The inputs must be already reduced modulo
$m$.
A quotient exists if and only if $g = \gcd(y, m)$ divides $x$. In that case the
quotients are exactly the numbers $\text{start} + \text{stride} \cdot i$ for $0 \leq
i < \text{length}$, where $\text{start}$ is the smallest quotient, $\text{stride} =
m/g$, and $\text{length} = g$. Unlike the quotient returned by
ModDiv, the result is canonical.
$f(x, y, m) = \operatorname{Some}((s, t, \ell))$, where $qy \equiv x \mod m$ if and only if $q = s + ti$ for some $0 \leq i < \ell$, if such $q$ exist.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits(): the
extended Euclidean algorithm on words performs $O(n)$ iterations of constant-cost
word operations, with no allocation.
§Panics
Panics if self or other are greater than or equal to m.
§Examples
See here.
type Output = u8
Source§impl ModDivList for u16
impl ModDivList for u16
Source§fn mod_div_list(self, other: u16, m: u16) -> Option<(u16, u16, u16)>
fn mod_div_list(self, other: u16, m: u16) -> Option<(u16, u16, u16)>
Finds all quotients of a number and another number modulo a third number $m$,
returning None if no quotient exists. The inputs must be already reduced modulo
$m$.
A quotient exists if and only if $g = \gcd(y, m)$ divides $x$. In that case the
quotients are exactly the numbers $\text{start} + \text{stride} \cdot i$ for $0 \leq
i < \text{length}$, where $\text{start}$ is the smallest quotient, $\text{stride} =
m/g$, and $\text{length} = g$. Unlike the quotient returned by
ModDiv, the result is canonical.
$f(x, y, m) = \operatorname{Some}((s, t, \ell))$, where $qy \equiv x \mod m$ if and only if $q = s + ti$ for some $0 \leq i < \ell$, if such $q$ exist.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits(): the
extended Euclidean algorithm on words performs $O(n)$ iterations of constant-cost
word operations, with no allocation.
§Panics
Panics if self or other are greater than or equal to m.
§Examples
See here.
type Output = u16
Source§impl ModDivList for u32
impl ModDivList for u32
Source§fn mod_div_list(self, other: u32, m: u32) -> Option<(u32, u32, u32)>
fn mod_div_list(self, other: u32, m: u32) -> Option<(u32, u32, u32)>
Finds all quotients of a number and another number modulo a third number $m$,
returning None if no quotient exists. The inputs must be already reduced modulo
$m$.
A quotient exists if and only if $g = \gcd(y, m)$ divides $x$. In that case the
quotients are exactly the numbers $\text{start} + \text{stride} \cdot i$ for $0 \leq
i < \text{length}$, where $\text{start}$ is the smallest quotient, $\text{stride} =
m/g$, and $\text{length} = g$. Unlike the quotient returned by
ModDiv, the result is canonical.
$f(x, y, m) = \operatorname{Some}((s, t, \ell))$, where $qy \equiv x \mod m$ if and only if $q = s + ti$ for some $0 \leq i < \ell$, if such $q$ exist.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits(): the
extended Euclidean algorithm on words performs $O(n)$ iterations of constant-cost
word operations, with no allocation.
§Panics
Panics if self or other are greater than or equal to m.
§Examples
See here.
type Output = u32
Source§impl ModDivList for u64
impl ModDivList for u64
Source§fn mod_div_list(self, other: u64, m: u64) -> Option<(u64, u64, u64)>
fn mod_div_list(self, other: u64, m: u64) -> Option<(u64, u64, u64)>
Finds all quotients of a number and another number modulo a third number $m$,
returning None if no quotient exists. The inputs must be already reduced modulo
$m$.
A quotient exists if and only if $g = \gcd(y, m)$ divides $x$. In that case the
quotients are exactly the numbers $\text{start} + \text{stride} \cdot i$ for $0 \leq
i < \text{length}$, where $\text{start}$ is the smallest quotient, $\text{stride} =
m/g$, and $\text{length} = g$. Unlike the quotient returned by
ModDiv, the result is canonical.
$f(x, y, m) = \operatorname{Some}((s, t, \ell))$, where $qy \equiv x \mod m$ if and only if $q = s + ti$ for some $0 \leq i < \ell$, if such $q$ exist.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits(): the
extended Euclidean algorithm on words performs $O(n)$ iterations of constant-cost
word operations, with no allocation.
§Panics
Panics if self or other are greater than or equal to m.
§Examples
See here.
type Output = u64
Source§impl ModDivList for u128
impl ModDivList for u128
Source§fn mod_div_list(self, other: u128, m: u128) -> Option<(u128, u128, u128)>
fn mod_div_list(self, other: u128, m: u128) -> Option<(u128, u128, u128)>
Finds all quotients of a number and another number modulo a third number $m$,
returning None if no quotient exists. The inputs must be already reduced modulo
$m$.
A quotient exists if and only if $g = \gcd(y, m)$ divides $x$. In that case the
quotients are exactly the numbers $\text{start} + \text{stride} \cdot i$ for $0 \leq
i < \text{length}$, where $\text{start}$ is the smallest quotient, $\text{stride} =
m/g$, and $\text{length} = g$. Unlike the quotient returned by
ModDiv, the result is canonical.
$f(x, y, m) = \operatorname{Some}((s, t, \ell))$, where $qy \equiv x \mod m$ if and only if $q = s + ti$ for some $0 \leq i < \ell$, if such $q$ exist.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits(): the
extended Euclidean algorithm on words performs $O(n)$ iterations of constant-cost
word operations, with no allocation.
§Panics
Panics if self or other are greater than or equal to m.
§Examples
See here.
type Output = u128
Source§impl ModDivList for usize
impl ModDivList for usize
Source§fn mod_div_list(self, other: usize, m: usize) -> Option<(usize, usize, usize)>
fn mod_div_list(self, other: usize, m: usize) -> Option<(usize, usize, usize)>
Finds all quotients of a number and another number modulo a third number $m$,
returning None if no quotient exists. The inputs must be already reduced modulo
$m$.
A quotient exists if and only if $g = \gcd(y, m)$ divides $x$. In that case the
quotients are exactly the numbers $\text{start} + \text{stride} \cdot i$ for $0 \leq
i < \text{length}$, where $\text{start}$ is the smallest quotient, $\text{stride} =
m/g$, and $\text{length} = g$. Unlike the quotient returned by
ModDiv, the result is canonical.
$f(x, y, m) = \operatorname{Some}((s, t, \ell))$, where $qy \equiv x \mod m$ if and only if $q = s + ti$ for some $0 \leq i < \ell$, if such $q$ exist.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits(): the
extended Euclidean algorithm on words performs $O(n)$ iterations of constant-cost
word operations, with no allocation.
§Panics
Panics if self or other are greater than or equal to m.
§Examples
See here.