Struct mod_int::ModInt

source ·
pub struct ModInt<const M: i64>(_);

Implementations§

source§

impl<const M: i64> ModInt<M>

source

pub fn new(x: i64) -> Self

整数を 0 <= x < modulo に正規化してインスタンスを作ります。

source

pub fn val(self) -> i64

ModInt に格納されている値を返します。

Examples
use mod_int::ModInt1000000007;
assert_eq!(ModInt1000000007::new(123).val(), 123);
source

pub fn modulo() -> i64

法を返します。

Examples
use mod_int::{ModInt1000000007, ModInt998244353};
assert_eq!(ModInt1000000007::modulo(), 1000000007);
assert_eq!(ModInt998244353::modulo(), 998244353);
source

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());
source

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>>> Add<T> for ModInt<M>

§

type Output = ModInt<M>

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
source§

impl<const M: i64, T: Into<ModInt<M>>> AddAssign<T> for ModInt<M>

source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
source§

impl<const M: i64> Clone for ModInt<M>

source§

fn clone(&self) -> ModInt<M>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const M: i64> Debug for ModInt<M>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const M: i64, T: Into<ModInt<M>>> Div<T> for ModInt<M>

§

type Output = ModInt<M>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<const M: i64, T: Into<ModInt<M>>> DivAssign<T> for ModInt<M>

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl<const M: i64> From<i16> for ModInt<M>

source§

fn from(x: i16) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<i32> for ModInt<M>

source§

fn from(x: i32) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<i64> for ModInt<M>

source§

fn from(x: i64) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<i8> for ModInt<M>

source§

fn from(x: i8) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<isize> for ModInt<M>

source§

fn from(x: isize) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<u16> for ModInt<M>

source§

fn from(x: u16) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<u32> for ModInt<M>

source§

fn from(x: u32) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<u64> for ModInt<M>

source§

fn from(x: u64) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<u8> for ModInt<M>

source§

fn from(x: u8) -> Self

Converts to this type from the input type.
source§

impl<const M: i64> From<usize> for ModInt<M>

source§

fn from(x: usize) -> Self

Converts to this type from the input type.
source§

impl<const M: i64, T: Into<ModInt<M>>> Mul<T> for ModInt<M>

§

type Output = ModInt<M>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<const M: i64, T: Into<ModInt<M>>> MulAssign<T> for ModInt<M>

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

impl<const M: i64, T: Into<ModInt<M>>> Sub<T> for ModInt<M>

§

type Output = ModInt<M>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
source§

impl<const M: i64, T: Into<ModInt<M>>> SubAssign<T> for ModInt<M>

source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
source§

impl<const M: i64> Copy for ModInt<M>

Auto Trait Implementations§

§

impl<const M: i64> RefUnwindSafe for ModInt<M>

§

impl<const M: i64> Send for ModInt<M>

§

impl<const M: i64> Sync for ModInt<M>

§

impl<const M: i64> Unpin for ModInt<M>

§

impl<const M: i64> UnwindSafe for ModInt<M>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.