Skip to main content

Gcd

Trait Gcd 

Source
pub trait Gcd {
    // Required method
    fn gcd(self, other: Self) -> Self;
}
Expand description

最大公約数。

§Complexity

$O(\log(\min\{m, n\}))$ time.

§Examples

use nekolib::math::Gcd;

assert_eq!(12_u32.gcd(18), 6);
assert_eq!(13_i32.gcd(-3), 1);
assert_eq!(60_u32.gcd(90).gcd(150), 30);

assert_eq!(0_u32.gcd(0), 0);
assert_eq!(0_u32.gcd(1), 1);

Required Methods§

Source

fn gcd(self, other: Self) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Gcd for i8

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for i16

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for i32

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for i64

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for i128

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for isize

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for u8

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for u16

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for u32

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for u64

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for u128

Source§

fn gcd(self, other: Self) -> Self

Source§

impl Gcd for usize

Source§

fn gcd(self, other: Self) -> Self

Implementors§