Struct DynamicModInt

Source
pub struct DynamicModInt<I> { /* private fields */ }
Expand description

Represents $\mathbb{Z}/m\mathbb{Z}$ where $m$ is a dynamic value.

Corresponds to atcoder::dynamic_modint in the original ACL.

§Example

use ac_library::ModInt as Mint;
use proconio::{input, source::once::OnceSource};

input! {
    from OnceSource::from("3 3 7\n"),
    a: u32,
    b: u32,
    m: u32,
}

Mint::set_modulus(m);
let a = Mint::new(a);
let b = Mint::new(b);

println!("{}", a * b); // `2`

Implementations§

Source§

impl<I: Id> DynamicModInt<I>

Source

pub fn modulus() -> u32

Returns the modulus.

Corresponds to atcoder::dynamic_modint::mod in the original ACL.

§Example
use ac_library::ModInt as Mint;

assert_eq!(998_244_353, Mint::modulus()); // default modulus
Source

pub fn set_modulus(modulus: u32)

Sets a modulus.

Corresponds to atcoder::dynamic_modint::set_mod in the original ACL.

§Constraints
  • This function must be called earlier than any other operation of Self.
§Example
use ac_library::ModInt as Mint;

Mint::set_modulus(7);
assert_eq!(7, Mint::modulus());
Source

pub fn new<T: RemEuclidU32>(val: T) -> Self

Creates a new DynamicModInt.

Takes any primitive integer.

Corresponds to the constructor of atcoder::dynamic_modint in the original ACL.

Source

pub fn raw(val: u32) -> Self

Constructs a DynamicModInt from a val < Self::modulus() without checking it.

Corresponds to atcoder::dynamic_modint::raw in the original ACL.

§Constraints
  • val is less than Self::modulus()

See ModIntBase::raw for more more details.

Source

pub fn val(self) -> u32

Retruns the representative.

Corresponds to atcoder::static_modint::val in the original ACL.

Source

pub fn pow(self, n: u64) -> Self

Returns self to the power of n.

Corresponds to atcoder::dynamic_modint::pow in the original ACL.

Source

pub fn inv(self) -> Self

Retruns the multiplicative inverse of self.

Corresponds to atcoder::dynamic_modint::inv in the original ACL.

§Panics

Panics if the multiplicative inverse does not exist.

Trait Implementations§

Source§

impl<I: Id> Add<&DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the + operation. Read more
Source§

impl<I: Id> Add<&DynamicModInt<I>> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the + operation. Read more
Source§

impl<I: Id> Add<DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the + operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> Add<T> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> DynamicModInt<I>

Performs the + operation. Read more
Source§

impl<I: Id> Add for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the + operation. Read more
Source§

impl<I: Id> AddAssign<&DynamicModInt<I>> for DynamicModInt<I>

Source§

fn add_assign(&mut self, rhs: &DynamicModInt<I>)

Performs the += operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> AddAssign<T> for DynamicModInt<I>

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<I: Id> AddAssign for DynamicModInt<I>

Source§

fn add_assign(&mut self, rhs: DynamicModInt<I>)

Performs the += operation. Read more
Source§

impl<I: Clone> Clone for DynamicModInt<I>

Source§

fn clone(&self) -> DynamicModInt<I>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<I: Id> Debug for DynamicModInt<I>

Source§

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

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

impl<I: Id> Default for DynamicModInt<I>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<I: Id> Display for DynamicModInt<I>

Source§

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

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

impl<I: Id> Div<&DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the / operation. Read more
Source§

impl<I: Id> Div<&DynamicModInt<I>> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the / operation. Read more
Source§

impl<I: Id> Div<DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the / operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> Div<T> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> DynamicModInt<I>

Performs the / operation. Read more
Source§

impl<I: Id> Div for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the / operation. Read more
Source§

impl<I: Id> DivAssign<&DynamicModInt<I>> for DynamicModInt<I>

Source§

fn div_assign(&mut self, rhs: &DynamicModInt<I>)

Performs the /= operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> DivAssign<T> for DynamicModInt<I>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<I: Id> DivAssign for DynamicModInt<I>

Source§

fn div_assign(&mut self, rhs: DynamicModInt<I>)

Performs the /= operation. Read more
Source§

impl<I: Id, V: RemEuclidU32> From<V> for DynamicModInt<I>

Source§

fn from(from: V) -> Self

Converts to this type from the input type.
Source§

impl<I: Id> FromStr for DynamicModInt<I>

Source§

type Err = Infallible

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Infallible>

Parses a string s to return a value of this type. Read more
Source§

impl<I: Id> Hash for DynamicModInt<I>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I: Id> ModIntBase for DynamicModInt<I>

These methods are implemented for the struct. You don’t need to use ModIntBase to call methods of DynamicModInt.

Source§

fn modulus() -> u32

Returns the modulus. Read more
Source§

fn raw(val: u32) -> Self

Constructs a Self from a val < Self::modulus() without checking it. Read more
Source§

fn val(self) -> u32

Retruns the representative. Read more
Source§

fn inv(self) -> Self

Retruns the multiplicative inverse of self. Read more
Source§

fn new<T: RemEuclidU32>(val: T) -> Self

Creates a new Self. Read more
Source§

fn pow(self, n: u64) -> Self

Returns self to the power of n. Read more
Source§

impl<I: Id> Mul<&DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the * operation. Read more
Source§

impl<I: Id> Mul<&DynamicModInt<I>> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the * operation. Read more
Source§

impl<I: Id> Mul<DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the * operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> Mul<T> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> DynamicModInt<I>

Performs the * operation. Read more
Source§

impl<I: Id> Mul for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the * operation. Read more
Source§

impl<I: Id> MulAssign<&DynamicModInt<I>> for DynamicModInt<I>

Source§

fn mul_assign(&mut self, rhs: &DynamicModInt<I>)

Performs the *= operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> MulAssign<T> for DynamicModInt<I>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<I: Id> MulAssign for DynamicModInt<I>

Source§

fn mul_assign(&mut self, rhs: DynamicModInt<I>)

Performs the *= operation. Read more
Source§

impl<I: Id> Neg for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the - operator.
Source§

fn neg(self) -> DynamicModInt<I>

Performs the unary - operation. Read more
Source§

impl<I: Id> Neg for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the - operator.
Source§

fn neg(self) -> DynamicModInt<I>

Performs the unary - operation. Read more
Source§

impl<I: PartialEq> PartialEq for DynamicModInt<I>

Source§

fn eq(&self, other: &DynamicModInt<I>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, I: Id> Product<&'a DynamicModInt<I>> for DynamicModInt<I>

Source§

fn product<S>(iter: S) -> Self
where S: Iterator<Item = &'a Self>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<I: Id> Product for DynamicModInt<I>

Source§

fn product<S>(iter: S) -> Self
where S: Iterator<Item = Self>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<I: Id> Sub<&DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the - operation. Read more
Source§

impl<I: Id> Sub<&DynamicModInt<I>> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &DynamicModInt<I>) -> DynamicModInt<I>

Performs the - operation. Read more
Source§

impl<I: Id> Sub<DynamicModInt<I>> for &DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the - operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> Sub<T> for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> DynamicModInt<I>

Performs the - operation. Read more
Source§

impl<I: Id> Sub for DynamicModInt<I>

Source§

type Output = DynamicModInt<I>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: DynamicModInt<I>) -> DynamicModInt<I>

Performs the - operation. Read more
Source§

impl<I: Id> SubAssign<&DynamicModInt<I>> for DynamicModInt<I>

Source§

fn sub_assign(&mut self, rhs: &DynamicModInt<I>)

Performs the -= operation. Read more
Source§

impl<I: Id, T: RemEuclidU32> SubAssign<T> for DynamicModInt<I>

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

impl<I: Id> SubAssign for DynamicModInt<I>

Source§

fn sub_assign(&mut self, rhs: DynamicModInt<I>)

Performs the -= operation. Read more
Source§

impl<'a, I: Id> Sum<&'a DynamicModInt<I>> for DynamicModInt<I>

Source§

fn sum<S>(iter: S) -> Self
where S: Iterator<Item = &'a Self>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<I: Id> Sum for DynamicModInt<I>

Source§

fn sum<S>(iter: S) -> Self
where S: Iterator<Item = Self>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<I: Copy> Copy for DynamicModInt<I>

Source§

impl<I: Eq> Eq for DynamicModInt<I>

Source§

impl<I> StructuralPartialEq for DynamicModInt<I>

Auto Trait Implementations§

§

impl<I> Freeze for DynamicModInt<I>

§

impl<I> RefUnwindSafe for DynamicModInt<I>

§

impl<I> Send for DynamicModInt<I>

§

impl<I> Sync for DynamicModInt<I>

§

impl<I> Unpin for DynamicModInt<I>

§

impl<I> UnwindSafe for DynamicModInt<I>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.