Trait ExtendedGcd

Source
pub trait ExtendedGcd<RHS = Self> {
    type Gcd;
    type Cofactor;

    // Required method
    fn extended_gcd(
        self,
        other: RHS,
    ) -> (Self::Gcd, Self::Cofactor, Self::Cofactor);
}
Expand description

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.

Required Associated Types§

Required Methods§

Source

fn extended_gcd(self, other: RHS) -> (Self::Gcd, Self::Cofactor, Self::Cofactor)

Implementations on Foreign Types§

Source§

impl ExtendedGcd for i8

Source§

fn extended_gcd(self, other: i8) -> (u8, i8, i8)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u8

Source§

type Cofactor = i8

Source§

impl ExtendedGcd for i16

Source§

fn extended_gcd(self, other: i16) -> (u16, i16, i16)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u16

Source§

type Cofactor = i16

Source§

impl ExtendedGcd for i32

Source§

fn extended_gcd(self, other: i32) -> (u32, i32, i32)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u32

Source§

type Cofactor = i32

Source§

impl ExtendedGcd for i64

Source§

fn extended_gcd(self, other: i64) -> (u64, i64, i64)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u64

Source§

type Cofactor = i64

Source§

impl ExtendedGcd for i128

Source§

fn extended_gcd(self, other: i128) -> (u128, i128, i128)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u128

Source§

type Cofactor = i128

Source§

impl ExtendedGcd for isize

Source§

fn extended_gcd(self, other: isize) -> (usize, isize, isize)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = usize

Source§

type Cofactor = isize

Source§

impl ExtendedGcd for u8

Source§

fn extended_gcd(self, other: u8) -> (u8, i8, i8)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u8

Source§

type Cofactor = i8

Source§

impl ExtendedGcd for u16

Source§

fn extended_gcd(self, other: u16) -> (u16, i16, i16)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u16

Source§

type Cofactor = i16

Source§

impl ExtendedGcd for u32

Source§

fn extended_gcd(self, other: u32) -> (u32, i32, i32)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u32

Source§

type Cofactor = i32

Source§

impl ExtendedGcd for u64

Source§

fn extended_gcd(self, other: u64) -> (u64, i64, i64)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u64

Source§

type Cofactor = i64

Source§

impl ExtendedGcd for u128

Source§

fn extended_gcd(self, other: u128) -> (u128, i128, i128)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = u128

Source§

type Cofactor = i128

Source§

impl ExtendedGcd for usize

Source§

fn extended_gcd(self, other: usize) -> (usize, isize, isize)

Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.

The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:

  • $f(0, 0) = (0, 0, 0)$.
  • $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§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(), other.significant_bits()).

§Examples

See here.

Source§

type Gcd = usize

Source§

type Cofactor = isize

Implementors§