Safe Haskell | None |
---|---|
Language | GHC2021 |
It is the struct that treats the modular arithmetic. All the remaining parts of AC Library works without modint, so you don't necessarily read this to use the remaining parts.
For most of the problems, it is sufficient to use ModInt998244353
, ModInt1000000007
, which
can be used as follows.
>>>
import AtCoder.ModInt qualified as M
>>>
type Mint = M.ModInt998244353
>>>
let modInt :: Int -> Mint; modInt = M.new
>>>
modInt 1000000000
1755647
Major changes from the original ac-library
DynamicModInt
is removed.
Since: 1.0.0
Synopsis
- class KnownNat a => Modulus (a :: Nat) where
- isPrimeModulus :: Proxy# a -> Bool
- primitiveRootModulus :: Proxy# a -> Int
- type ModInt998244353 = ModInt 998244353
- type ModInt1000000007 = ModInt 1000000007
- modVal :: forall (a :: Nat). KnownNat a => Proxy a -> Int
- modVal# :: forall (a :: Nat). KnownNat a => Proxy# a -> Int
- newtype ModInt (a :: k) = ModInt {}
- new :: forall (a :: Nat). KnownNat a => Int -> ModInt a
- new32 :: forall (a :: Nat). KnownNat a => Word32 -> ModInt a
- new64 :: forall (a :: Nat). KnownNat a => Word32 -> ModInt a
- unsafeNew :: forall (a :: Nat). KnownNat a => Word32 -> ModInt a
- modulus :: forall (a :: Nat). KnownNat a => ModInt a -> Int
- val :: forall (a :: Nat). KnownNat a => ModInt a -> Int
- val32 :: forall (a :: Nat). KnownNat a => ModInt a -> Word32
- val64 :: forall (a :: Nat). KnownNat a => ModInt a -> Word32
- pow :: forall (a :: Nat). (HasCallStack, KnownNat a) => ModInt a -> Int -> ModInt a
- inv :: forall (a :: Nat). (HasCallStack, Modulus a) => ModInt a -> ModInt a
Modulus
class KnownNat a => Modulus (a :: Nat) where #
KnownNat
with meta information used for modulus.
Since: 1.0.0
isPrimeModulus :: Proxy# a -> Bool #
Returns if the modulus is a prime value.
Since: 1.0.0
primitiveRootModulus :: Proxy# a -> Int #
Returns the primitive root of the modulus value. Note that the default implementation is slow.
Since: 1.0.0
Instances
Modulus 167772161 # | \(2^{24} - 1\). Since: 1.0.0 |
Defined in AtCoder.ModInt isPrimeModulus :: Proxy# 167772161 -> Bool # primitiveRootModulus :: Proxy# 167772161 -> Int # | |
Modulus 469762049 # | \(2^{25} - 1\). Since: 1.0.0 |
Defined in AtCoder.ModInt isPrimeModulus :: Proxy# 469762049 -> Bool # primitiveRootModulus :: Proxy# 469762049 -> Int # | |
Modulus 754974721 # | \(2^{26} - 1\). Since: 1.0.0 |
Defined in AtCoder.ModInt isPrimeModulus :: Proxy# 754974721 -> Bool # primitiveRootModulus :: Proxy# 754974721 -> Int # | |
Modulus 998244353 # | \(119 \times 2^{23} + 1\). It is often used in contest problems Since: 1.0.0 |
Defined in AtCoder.ModInt isPrimeModulus :: Proxy# 998244353 -> Bool # primitiveRootModulus :: Proxy# 998244353 -> Int # | |
Modulus 1000000007 # | It used to be used in contest problems. Since: 1.0.0 |
Defined in AtCoder.ModInt isPrimeModulus :: Proxy# 1000000007 -> Bool # primitiveRootModulus :: Proxy# 1000000007 -> Int # | |
Modulus 2147483647 # | \(2^{31} - 1\), suitable for boundary testing. Since: 1.0.0 |
Defined in AtCoder.ModInt isPrimeModulus :: Proxy# 2147483647 -> Bool # primitiveRootModulus :: Proxy# 2147483647 -> Int # |
type ModInt998244353 = ModInt 998244353 #
ModInt
with modulus value 998244353
.
Since: 1.0.0
type ModInt1000000007 = ModInt 1000000007 #
ModInt
with modulus value 1000000007
.
Since: 1.0.0
Helpers
ModInt
Word32
value that treats the modula arithmetic.
Instances
Constructors
Safe constructors
Unsafe constructor
unsafeNew :: forall (a :: Nat). KnownNat a => Word32 -> ModInt a #
Creates ModInt
without taking mod. It is the function for constant-factor speedup.
Constraints
- \(0 \leq x \lt \mathrm{mod}\) (not asserted at runtime)
Since: 1.0.0
Accessors
Modulus value
Internal value
val32 :: forall (a :: Nat). KnownNat a => ModInt a -> Word32 #
Returns the internal value as Word32
without type conversion. It is the function for
constant-factor speedup.
Complecity
- \(O(1)\)
Since: 1.0.0