Trait Multifactorial

Source
pub trait Multifactorial {
    // Required method
    fn multifactorial(n: u64, m: u64) -> Self;
}
Expand description

Computes the $m$-multifactorial of a u64. The $m$-multifactorial of a non-negative integer $n$ is the product of all integers $k$ such that $0<k\leq n$ and $k\equiv n \pmod m$.

Required Methods§

Source

fn multifactorial(n: u64, m: u64) -> 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 Multifactorial for u8

Source§

fn multifactorial(n: u64, m: u64) -> u8

Computes a multifactorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_multifactorial.

$$ f(n, m) = n!^{(m)} = n \times (n - m) \times (n - 2m) \times \cdots \times i. $$ If $n$ is divisible by $m$, then $i$ is $m$; otherwise, $i$ is the remainder when $n$ is divided by $m$.

$n!^{(m)} = O(\sqrt{n}(n/e)^{n/m})$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Multifactorial for u16

Source§

fn multifactorial(n: u64, m: u64) -> u16

Computes a multifactorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_multifactorial.

$$ f(n, m) = n!^{(m)} = n \times (n - m) \times (n - 2m) \times \cdots \times i. $$ If $n$ is divisible by $m$, then $i$ is $m$; otherwise, $i$ is the remainder when $n$ is divided by $m$.

$n!^{(m)} = O(\sqrt{n}(n/e)^{n/m})$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Multifactorial for u32

Source§

fn multifactorial(n: u64, m: u64) -> u32

Computes a multifactorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_multifactorial.

$$ f(n, m) = n!^{(m)} = n \times (n - m) \times (n - 2m) \times \cdots \times i. $$ If $n$ is divisible by $m$, then $i$ is $m$; otherwise, $i$ is the remainder when $n$ is divided by $m$.

$n!^{(m)} = O(\sqrt{n}(n/e)^{n/m})$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Multifactorial for u64

Source§

fn multifactorial(n: u64, m: u64) -> u64

Computes a multifactorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_multifactorial.

$$ f(n, m) = n!^{(m)} = n \times (n - m) \times (n - 2m) \times \cdots \times i. $$ If $n$ is divisible by $m$, then $i$ is $m$; otherwise, $i$ is the remainder when $n$ is divided by $m$.

$n!^{(m)} = O(\sqrt{n}(n/e)^{n/m})$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Multifactorial for u128

Source§

fn multifactorial(n: u64, m: u64) -> u128

Computes a multifactorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_multifactorial.

$$ f(n, m) = n!^{(m)} = n \times (n - m) \times (n - 2m) \times \cdots \times i. $$ If $n$ is divisible by $m$, then $i$ is $m$; otherwise, $i$ is the remainder when $n$ is divided by $m$.

$n!^{(m)} = O(\sqrt{n}(n/e)^{n/m})$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Multifactorial for usize

Source§

fn multifactorial(n: u64, m: u64) -> usize

Computes a multifactorial of a number.

If the input is too large, the function panics. For a function that returns None instead, try checked_multifactorial.

$$ f(n, m) = n!^{(m)} = n \times (n - m) \times (n - 2m) \times \cdots \times i. $$ If $n$ is divisible by $m$, then $i$ is $m$; otherwise, $i$ is the remainder when $n$ is divided by $m$.

$n!^{(m)} = O(\sqrt{n}(n/e)^{n/m})$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Implementors§