|
template<typename T , std::enable_if_t< std::is_integral_v< T > &&std::is_signed_v< T > > * = nullptr> |
| BarrettModInt (T x) |
| Converts a plain integer to a Barrett modular integer.
|
|
template<typename T , std::enable_if_t< std::is_unsigned_v< T > > * = nullptr> |
| BarrettModInt (T x) |
| Converts a plain integer to a Barrett modular integer.
|
|
int_type | val () const |
| Converts back to a plain integer in the range \([0,N)\).
|
|
int_type | residue () const |
| Returns a number that is the same for the same residue class modulo the modulus.
|
|
mint & | operator++ () |
|
mint | operator++ (int) |
|
mint | operator+ () const |
|
mint | operator+ (const mint &rhs) const |
|
mint & | operator+= (const mint &rhs) |
|
mint & | operator-- () |
|
mint | operator-- (int) |
|
mint | operator- () const |
|
mint | operator- (const mint &rhs) const |
|
mint & | operator-= (const mint &rhs) |
|
mint | operator* (const mint &rhs) const |
|
mint & | operator*= (const mint &rhs) |
|
mint | inv () const |
| Returns the modular inverse.
|
|
mint | operator/ (const mint &rhs) const |
|
mint & | operator/= (const mint &rhs) |
|
bool | operator== (const mint &rhs) const |
|
bool | operator!= (const mint &rhs) const |
|
|
(Note that these are not member functions.)
|
template<uint32_t Mod> |
using | BMInt = BarrettModInt< impl::StaticBarrettReductionContext< uint32_t, Mod > > |
| Type alias for 32-bit BarrettModInt with compile-time constant modulus.
|
|
template<uint64_t Mod> |
using | BMInt64 = BarrettModInt< impl::StaticBarrettReductionContext< uint64_t, Mod > > |
| Type alias for 64-bit BarrettModInt with compile-time constant modulus.
|
|
using | DynamicBMInt = BarrettModInt< impl::DynamicBarrettReductionContext< uint32_t > > |
| Type alias for dynamic BarrettModInt with modulus less than \(2^{32}\).
|
|
using | DynamicBMInt64 = BarrettModInt< impl::DynamicBarrettReductionContext< uint64_t > > |
| Type alias for dynamic BarrettModInt with modulus less than \(2^{64}\).
|
|
template<typename Context>
class cplib::BarrettModInt< Context >
Modular integer using Barrett reduction.
Your code should generally use the type alias BMInt or BMInt64 for compile-time static modulus, and DynamicBMInt or DynamicBMInt64 for run-time dynamic modulus.
Barrett reduction is used for modular multiplication to avoid costly division. Unlike Montgomery reduction, it works for any modulus, but is slightly slower.
- See also
- MontgomeryModInt
template<typename Context >
template<typename T , std::enable_if_t< std::is_integral_v< T > &&std::is_signed_v< T > > * = nullptr>
Converts a plain integer to a Barrett modular integer.
This constructor is marked explicit
because the cost of conversion is non-trivial (requires one Barrett reduction) and thus implicit conversion is discouraged.
template<typename Context >
template<typename T , std::enable_if_t< std::is_unsigned_v< T > > * = nullptr>
Converts a plain integer to a Barrett modular integer.
This constructor is marked explicit
because the cost of conversion is non-trivial (requires one Barrett reduction) and thus implicit conversion is discouraged.
template<typename Context >
Set the dynamic modint's modulus.
Calling this for static modint would be a compile error.
It maintains a stack of moduli. Push stack when it is called, and pop stack when the returned guard object is destructed. This allows recursively calling functions that use different moduli. However at any given moment you can only use one modulus.
- Parameters
-