Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
AtCoder.ModInt
Description
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 where
- isPrimeModulus :: Proxy# a -> Bool
- primitiveRootModulus :: Proxy# a -> Int
- type ModInt998244353 = ModInt 998244353
- type ModInt1000000007 = ModInt 1000000007
- modVal :: forall a. KnownNat a => Proxy a -> Int
- modVal# :: forall a. KnownNat a => Proxy# a -> Int
- newtype ModInt a = ModInt {}
- new :: forall a. KnownNat a => Int -> ModInt a
- new32 :: forall a. KnownNat a => Word32 -> ModInt a
- new64 :: forall a. KnownNat a => Word64 -> ModInt a
- unsafeNew :: KnownNat a => Word32 -> ModInt a
- modulus :: forall a. KnownNat a => ModInt a -> Int
- val :: KnownNat a => ModInt a -> Int
- val32 :: KnownNat a => ModInt a -> Word32
- val64 :: KnownNat a => ModInt a -> Word64
- pow :: forall a. (HasCallStack, KnownNat a) => ModInt a -> Int -> ModInt a
- inv :: forall a. (HasCallStack, Modulus a) => ModInt a -> ModInt a
Modulus
class KnownNat a => Modulus a where Source #
KnownNat
with meta information used for modulus.
Since: 1.0.0
Minimal complete definition
Methods
isPrimeModulus :: Proxy# a -> Bool Source #
Returns if the modulus is a prime value.
Since: 1.0.0
primitiveRootModulus :: Proxy# a -> Int Source #
Returns the primitive root of the modulus value. Note that the default implementation is slow.
Since: 1.0.0
Instances
Modulus 167772161 Source # | \(2^{24} - 1\). Since: 1.0.0 |
Defined in AtCoder.ModInt Methods isPrimeModulus :: Proxy# 167772161 -> Bool Source # primitiveRootModulus :: Proxy# 167772161 -> Int Source # | |
Modulus 469762049 Source # | \(2^{25} - 1\). Since: 1.0.0 |
Defined in AtCoder.ModInt Methods isPrimeModulus :: Proxy# 469762049 -> Bool Source # primitiveRootModulus :: Proxy# 469762049 -> Int Source # | |
Modulus 754974721 Source # | \(2^{26} - 1\). Since: 1.0.0 |
Defined in AtCoder.ModInt Methods isPrimeModulus :: Proxy# 754974721 -> Bool Source # primitiveRootModulus :: Proxy# 754974721 -> Int Source # | |
Modulus 998244353 Source # | \(119 \times 2^{23} + 1\). It is often used in contest problems Since: 1.0.0 |
Defined in AtCoder.ModInt Methods isPrimeModulus :: Proxy# 998244353 -> Bool Source # primitiveRootModulus :: Proxy# 998244353 -> Int Source # | |
Modulus 1000000007 Source # | It used to be used in contest problems. Since: 1.0.0 |
Defined in AtCoder.ModInt Methods isPrimeModulus :: Proxy# 1000000007 -> Bool Source # primitiveRootModulus :: Proxy# 1000000007 -> Int Source # | |
Modulus 2147483647 Source # | \(2^{31} - 1\), suitable for boundary testing. Since: 1.0.0 |
Defined in AtCoder.ModInt Methods isPrimeModulus :: Proxy# 2147483647 -> Bool Source # primitiveRootModulus :: Proxy# 2147483647 -> Int Source # |
type ModInt998244353 = ModInt 998244353 Source #
ModInt
with modulus value 998244353
.
Since: 1.0.0
type ModInt1000000007 = ModInt 1000000007 Source #
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 :: KnownNat a => Word32 -> ModInt a Source #
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 :: KnownNat a => ModInt a -> Word32 Source #
Returns the internal value as Word32
without type conversion. It is the function for
constant-factor speedup.
Complecity
- \(O(1)\)
Since: 1.0.0