Trait nekolib::math::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

Implementations on Foreign Types§

source§

impl Gcd for u32

source§

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

source§

impl Gcd for i64

source§

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

source§

impl Gcd for u16

source§

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

source§

impl Gcd for isize

source§

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

source§

impl Gcd for i128

source§

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

source§

impl Gcd for u128

source§

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

source§

impl Gcd for i8

source§

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

source§

impl Gcd for usize

source§

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

source§

impl Gcd for i32

source§

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

source§

impl Gcd for i16

source§

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

source§

impl Gcd for u64

source§

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

source§

impl Gcd for u8

source§

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

Implementors§