pub struct ModInt<const M: i64>(_);
Implementations§
source§impl<const M: i64> ModInt<M>
impl<const M: i64> ModInt<M>
sourcepub fn val(self) -> i64
pub fn val(self) -> i64
ModInt
に格納されている値を返します。
Examples
use mod_int::ModInt1000000007;
assert_eq!(ModInt1000000007::new(123).val(), 123);
sourcepub fn modulo() -> i64
pub fn modulo() -> i64
法を返します。
Examples
use mod_int::{ModInt1000000007, ModInt998244353};
assert_eq!(ModInt1000000007::modulo(), 1000000007);
assert_eq!(ModInt998244353::modulo(), 998244353);
sourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
二分累乗法で x^exp % p
を計算します。
Examples
use mod_int::ModInt1000000007;
use std::iter::repeat;
let (x, exp, p) = (123, 100_u32, 1000000007);
let y = repeat(x).take(exp as usize).fold(1, |acc, x| acc * x % p);
assert_eq!(y, ModInt1000000007::new(x).pow(exp).val());
sourcepub fn inv(self) -> Self
pub fn inv(self) -> Self
x * y % p = 1
となる y
を返します。
Examples
use mod_int::ModInt1000000007;
let (x, p) = (2, ModInt1000000007::modulo());
let y = ModInt1000000007::new(x).inv().val();
assert_eq!(x * y % p, 1);
ⓘ
use mod_int::ModInt1000000007;
ModInt1000000007::new(0).inv(); // panic
ⓘ
use mod_int::ModInt;
// 6 * n % 10 : 0, 6, 2, 8, 4, 0, 6, 2, 8, 4
ModInt::<10>::new(6).inv(); // panic
Trait Implementations§
source§impl<const M: i64, T: Into<ModInt<M>>> AddAssign<T> for ModInt<M>
impl<const M: i64, T: Into<ModInt<M>>> AddAssign<T> for ModInt<M>
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the
+=
operation. Read moresource§impl<const M: i64, T: Into<ModInt<M>>> DivAssign<T> for ModInt<M>
impl<const M: i64, T: Into<ModInt<M>>> DivAssign<T> for ModInt<M>
source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the
/=
operation. Read moresource§impl<const M: i64, T: Into<ModInt<M>>> MulAssign<T> for ModInt<M>
impl<const M: i64, T: Into<ModInt<M>>> MulAssign<T> for ModInt<M>
source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the
*=
operation. Read moresource§impl<const M: i64, T: Into<ModInt<M>>> SubAssign<T> for ModInt<M>
impl<const M: i64, T: Into<ModInt<M>>> SubAssign<T> for ModInt<M>
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the
-=
operation. Read more