pub trait CarmichaelLambda {
    // Required method
    fn carmichael_lambda(self) -> Self;
}
Expand description

Carmichael の λ\lambda 関数。

λ(n)\lambda(n) は、gcd(a,n)\gcd(a, n) である任意の aa に対して am1(modn)a^m\equiv 1 \pmod{n} となる最小の mm として定義される。

$\gdef{\lcm}{\operatorname*{lcm}}$ 以下の式によって計算される。

  • λ(1)=1\lambda(1) = 1
  • λ(2)=1\lambda(2) = 1
  • λ(4)=2\lambda(4) = 2
  • λ(2e)=2e2\lambda(2^e) = 2^{e-2} for e3e\ge 3
  • λ(pe)=φ(pe)=pe1(p1)\lambda(p^e) = \varphi(p^e) = p^{e-1}(p-1) for odd prime pp
  • $\lambda(\prod_{p:\text{ prime}} p_i^{e_i}) = \lcm_i \lambda(p_i^{e_i})$

Complexity

O(n)O(\sqrt{n}) time.

Examples

use nekolib::math::CarmichaelLambda;

assert_eq!(1_u64.carmichael_lambda(), 1);
assert_eq!(15_u64.carmichael_lambda(), 4);
assert_eq!(21_u64.carmichael_lambda(), 6);
assert_eq!(33_u64.carmichael_lambda(), 10);

Required Methods§

source

fn carmichael_lambda(self) -> Self

Implementations on Foreign Types§

source§

impl CarmichaelLambda for u32

source§

fn carmichael_lambda(self) -> Self

source§

impl CarmichaelLambda for u8

source§

fn carmichael_lambda(self) -> Self

source§

impl CarmichaelLambda for u16

source§

fn carmichael_lambda(self) -> Self

source§

impl CarmichaelLambda for u128

source§

fn carmichael_lambda(self) -> Self

source§

impl CarmichaelLambda for u64

source§

fn carmichael_lambda(self) -> Self

source§

impl CarmichaelLambda for usize

source§

fn carmichael_lambda(self) -> Self

Implementors§