Skip to content

Commit ca2b2ef

Browse files
authored
[auto-verifier] docs commit 9a95075
1 parent f716b2f commit ca2b2ef

40 files changed

+2056
-792
lines changed

index.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@ data:
5252
pages:
5353
- icon: ':heavy_check_mark:'
5454
path: weilycoder/poly/fft.hpp
55-
title: Implementation of Fast Fourier Transform (FFT) and its inverse.
55+
title: Fast Fourier Transform (FFT) implementation
5656
- icon: ':heavy_check_mark:'
5757
path: weilycoder/poly/fft_convolve.hpp
58-
title: Functions for performing convolution using Fast Fourier Transform (FFT).
58+
title: Multiplying polynomials using Fast Fourier Transform (FFT)
5959
- icon: ':heavy_check_mark:'
6060
path: weilycoder/poly/fft_utility.hpp
6161
title: Utility functions and constants for Fast Fourier Transform (FFT)
6262
- icon: ':heavy_check_mark:'
6363
path: weilycoder/poly/karatsuba.hpp
6464
title: Multiply two polynomials using the Karatsuba algorithm.
65+
- icon: ':heavy_check_mark:'
66+
path: weilycoder/poly/mtt_convolve.hpp
67+
title: Multiply two polynomials under modulo using MTT with 3 NTT-friendly moduli.
6568
- icon: ':heavy_check_mark:'
6669
path: weilycoder/poly/ntt.hpp
67-
title: Number Theoretic Transform (NTT)
70+
title: Number Theoretic Transform (NTT) implementation
6871
- icon: ':heavy_check_mark:'
6972
path: weilycoder/poly/ntt_convolve.hpp
70-
title: weilycoder/poly/ntt_convolve.hpp
73+
title: Multiplying polynomials using Number Theoretic Transform (NTT)
7174
verificationCategories:
7275
- name: test
7376
pages:
@@ -80,6 +83,9 @@ data:
8083
- icon: ':heavy_check_mark:'
8184
path: test/convolution_mod.test.cpp
8285
title: test/convolution_mod.test.cpp
86+
- icon: ':heavy_check_mark:'
87+
path: test/convolution_mod_1000000007.test.cpp
88+
title: test/convolution_mod_1000000007.test.cpp
8389
- icon: ':heavy_check_mark:'
8490
path: test/convolution_mod_2_64.test.cpp
8591
title: test/convolution_mod_2_64.test.cpp

test/aplusb.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ data:
160160
isVerificationFile: true
161161
path: test/aplusb.test.cpp
162162
requiredBy: []
163-
timestamp: '2025-11-07 09:14:02+08:00'
163+
timestamp: '2025-11-07 22:54:43+08:00'
164164
verificationStatus: TEST_ACCEPTED
165165
verifiedWith: []
166166
documentation_of: test/aplusb.test.cpp

test/biconnected_components.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ data:
112112
isVerificationFile: true
113113
path: test/biconnected_components.test.cpp
114114
requiredBy: []
115-
timestamp: '2025-11-07 09:14:02+08:00'
115+
timestamp: '2025-11-07 22:54:43+08:00'
116116
verificationStatus: TEST_ACCEPTED
117117
verifiedWith: []
118118
documentation_of: test/biconnected_components.test.cpp

test/convolution_mod.test.cpp.md

Lines changed: 92 additions & 57 deletions
Large diffs are not rendered by default.

test/convolution_mod_1000000007.test.cpp.md

Lines changed: 389 additions & 0 deletions
Large diffs are not rendered by default.

test/convolution_mod_2_64.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ data:
9595
isVerificationFile: true
9696
path: test/convolution_mod_2_64.test.cpp
9797
requiredBy: []
98-
timestamp: '2025-11-07 09:14:02+08:00'
98+
timestamp: '2025-11-07 22:54:43+08:00'
9999
verificationStatus: TEST_ACCEPTED
100100
verifiedWith: []
101101
documentation_of: test/convolution_mod_2_64.test.cpp

test/factorize.test.cpp.md

Lines changed: 98 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -47,68 +47,106 @@ data:
4747
\ weilycoder\n\n\n#line 1 \"weilycoder/number-theory/mod_utility.hpp\"\n\n\n\n\
4848
/**\n * @file mod_utility.hpp\n * @brief Modular Arithmetic Utilities\n */\n\n\
4949
#line 10 \"weilycoder/number-theory/mod_utility.hpp\"\n\nnamespace weilycoder\
50-
\ {\nusing u128 = unsigned __int128;\n\ntemplate <bool bit32 = false>\nconstexpr\
51-
\ uint64_t mod_add(uint64_t a, uint64_t b, uint64_t modulus) {\n if constexpr\
52-
\ (bit32) {\n uint64_t res = a + b;\n if (res >= modulus)\n res -=\
53-
\ modulus;\n return res;\n } else {\n u128 res = static_cast<u128>(a) +\
54-
\ b;\n if (res >= modulus)\n res -= modulus;\n return res;\n }\n}\n\
55-
\ntemplate <bool bit32 = false>\nconstexpr uint64_t mod_sub(uint64_t a, uint64_t\
56-
\ b, uint64_t modulus) {\n if constexpr (bit32) {\n uint64_t res = (a >= b)\
57-
\ ? (a - b) : (modulus + a - b);\n return res;\n } else {\n u128 res =\
58-
\ (a >= b) ? (a - b) : (static_cast<u128>(modulus) + a - b);\n return res;\n\
59-
\ }\n}\n\n/**\n * @brief Perform modular multiplication for 64-bit integers.\n\
60-
\ * @tparam bit32 If true, won't use 128-bit arithmetic. You should ensure that\n\
61-
\ * all inputs are small enough to avoid overflow (i.e. bit-32).\n * @param\
62-
\ a The first multiplicand.\n * @param b The second multiplicand.\n * @param modulus\
63-
\ The modulus.\n * @return (a * b) % modulus\n */\ntemplate <bool bit32 = false>\n\
64-
constexpr uint64_t mod_mul(uint64_t a, uint64_t b, uint64_t modulus) {\n if constexpr\
65-
\ (bit32)\n return a * b % modulus;\n else\n return static_cast<u128>(a)\
66-
\ * b % modulus;\n}\n\n/**\n * @brief Perform modular multiplication for 64-bit\
50+
\ {\nusing u128 = unsigned __int128;\n\n/**\n * @brief Perform modular addition\
51+
\ for 64-bit integers.\n * @tparam bit32 If true, won't use 128-bit arithmetic.\
52+
\ You should ensure that\n * all inputs are small enough to avoid overflow\
53+
\ (i.e. bit-32).\n * @param a The first addend.\n * @param b The second addend.\n\
54+
\ * @param modulus The modulus.\n * @return (a + b) % modulus\n */\ntemplate <bool\
55+
\ bit32 = false>\nconstexpr uint64_t mod_add(uint64_t a, uint64_t b, uint64_t\
56+
\ modulus) {\n if constexpr (bit32) {\n uint64_t res = a + b;\n if (res\
57+
\ >= modulus)\n res -= modulus;\n return res;\n } else {\n u128 res\
58+
\ = static_cast<u128>(a) + b;\n if (res >= modulus)\n res -= modulus;\n\
59+
\ return res;\n }\n}\n\n/**\n * @brief Perform modular addition for 64-bit\
6760
\ integers with a compile-time\n * modulus.\n * @tparam Modulus The modulus.\n\
68-
\ * @tparam bit32 If true, won't use 128-bit arithmetic. You should ensure that\n\
69-
\ * all inputs are small enough to avoid overflow (i.e. bit-32).\n * @param\
70-
\ a The first multiplicand.\n * @param b The second multiplicand.\n * @return\
71-
\ (a * b) % Modulus\n */\ntemplate <uint64_t Modulus, bool bit32 = false>\nconstexpr\
72-
\ uint64_t mod_mul(uint64_t a, uint64_t b) {\n if constexpr (bit32)\n return\
73-
\ a * b % Modulus;\n else\n return static_cast<u128>(a) * b % Modulus;\n}\n\
74-
\n/**\n * @brief Perform modular exponentiation for 64-bit integers.\n * @tparam\
75-
\ bit32 If true, won't use 128-bit arithmetic. You should ensure that\n * \
76-
\ all inputs are small enough to avoid overflow (i.e. bit-32).\n * @param\
77-
\ base The base number.\n * @param exponent The exponent.\n * @param modulus The\
78-
\ modulus.\n * @return (base^exponent) % modulus\n */\ntemplate <bool bit32 =\
79-
\ false>\nconstexpr uint64_t mod_pow(uint64_t base, uint64_t exponent, uint64_t\
80-
\ modulus) {\n uint64_t result = 1 % modulus;\n base %= modulus;\n while (exponent\
81-
\ > 0) {\n if (exponent & 1)\n result = mod_mul<bit32>(result, base, modulus);\n\
82-
\ base = mod_mul<bit32>(base, base, modulus);\n exponent >>= 1;\n }\n \
83-
\ return result;\n}\n} // namespace weilycoder\n\n\n#line 1 \"weilycoder/number-theory/prime.hpp\"\
84-
\n\n\n\n/**\n * @file prime.hpp\n * @brief Prime Number Utilities\n */\n\n#line\
85-
\ 11 \"weilycoder/number-theory/prime.hpp\"\n#include <type_traits>\n\nnamespace\
86-
\ weilycoder {\n/**\n * @brief Miller-Rabin primality test for a given base.\n\
87-
\ * @tparam bit32 If true, won't use 128-bit arithmetic. You should ensure that\n\
88-
\ * all inputs are small enough to avoid overflow (i.e. bit-32).\n * @tparam\
89-
\ base The base to test.\n * @param n The number to test for primality.\n * @param\
90-
\ d An odd component of n-1 (n-1 = d * 2^s).\n * @param s The exponent of 2 in\
91-
\ the factorization of n-1.\n * @return true if n is probably prime for the given\
92-
\ base, false if composite.\n */\ntemplate <bool bit32, uint64_t base>\nconstexpr\
93-
\ bool miller_rabin_test(uint64_t n, uint64_t d, uint32_t s) {\n uint64_t x =\
94-
\ mod_pow<bit32>(base, d, n);\n if (x == 0 || x == 1 || x == n - 1)\n return\
95-
\ true;\n for (uint32_t r = 1; r < s; ++r) {\n x = mod_mul<bit32>(x, x, n);\n\
96-
\ if (x == n - 1)\n return true;\n }\n return false;\n}\n\n/**\n * @brief\
97-
\ Variadic template to test multiple bases in Miller-Rabin test.\n * @tparam bit32\
98-
\ If true, won't use 128-bit arithmetic. You should ensure that\n * all\
99-
\ inputs are small enough to avoid overflow (i.e. bit-32).\n * @tparam base The\
100-
\ first base to test.\n * @tparam Rest The remaining bases to test.\n * @param\
61+
\ * @param a The first addend.\n * @param b The second addend.\n * @return (a\
62+
\ + b) % Modulus\n */\ntemplate <uint64_t Modulus> constexpr uint64_t mod_add(uint64_t\
63+
\ a, uint64_t b) {\n if constexpr (Modulus <= UINT32_MAX) {\n uint64_t res\
64+
\ = a + b;\n if (res >= Modulus)\n res -= Modulus;\n return res;\n\
65+
\ } else {\n u128 res = static_cast<u128>(a) + b;\n if (res >= Modulus)\n\
66+
\ res -= Modulus;\n return res;\n }\n}\n\n/**\n * @brief Perform modular\
67+
\ subtraction for 64-bit integers.\n * @tparam bit32 If true, won't use 128-bit\
68+
\ arithmetic. You should ensure that\n * all inputs are small enough to\
69+
\ avoid overflow (i.e. bit-32).\n * @param a The minuend.\n * @param b The subtrahend.\n\
70+
\ * @param modulus The modulus.\n * @return (a - b) % modulus\n */\ntemplate <bool\
71+
\ bit32 = false>\nconstexpr uint64_t mod_sub(uint64_t a, uint64_t b, uint64_t\
72+
\ modulus) {\n if constexpr (bit32) {\n uint64_t res = (a >= b) ? (a - b)\
73+
\ : (modulus + a - b);\n return res;\n } else {\n u128 res = (a >= b) ?\
74+
\ (a - b) : (static_cast<u128>(modulus) + a - b);\n return res;\n }\n}\n\n\
75+
/**\n * @brief Perform modular subtraction for 64-bit integers with a compile-time\n\
76+
\ * modulus.\n * @tparam Modulus The modulus.\n * @param a The minuend.\n\
77+
\ * @param b The subtrahend.\n * @return (a - b) % Modulus\n */\ntemplate <uint64_t\
78+
\ Modulus> constexpr uint64_t mod_sub(uint64_t a, uint64_t b) {\n if constexpr\
79+
\ (Modulus <= UINT32_MAX) {\n uint64_t res = (a >= b) ? (a - b) : (Modulus\
80+
\ + a - b);\n return res;\n } else {\n u128 res = (a >= b) ? (a - b) :\
81+
\ (static_cast<u128>(Modulus) + a - b);\n return res;\n }\n}\n\n/**\n * @brief\
82+
\ Perform modular multiplication for 64-bit integers.\n * @tparam bit32 If true,\
83+
\ won't use 128-bit arithmetic. You should ensure that\n * all inputs\
84+
\ are small enough to avoid overflow (i.e. bit-32).\n * @param a The first multiplicand.\n\
85+
\ * @param b The second multiplicand.\n * @param modulus The modulus.\n * @return\
86+
\ (a * b) % modulus\n */\ntemplate <bool bit32 = false>\nconstexpr uint64_t mod_mul(uint64_t\
87+
\ a, uint64_t b, uint64_t modulus) {\n if constexpr (bit32)\n return a * b\
88+
\ % modulus;\n else\n return static_cast<u128>(a) * b % modulus;\n}\n\n/**\n\
89+
\ * @brief Perform modular multiplication for 64-bit integers with a compile-time\n\
90+
\ * modulus.\n * @tparam Modulus The modulus.\n * @param a The first multiplicand.\n\
91+
\ * @param b The second multiplicand.\n * @return (a * b) % Modulus\n */\ntemplate\
92+
\ <uint64_t Modulus> constexpr uint64_t mod_mul(uint64_t a, uint64_t b) {\n if\
93+
\ constexpr (Modulus <= UINT32_MAX)\n return a * b % Modulus;\n else\n \
94+
\ return static_cast<u128>(a) * b % Modulus;\n}\n\n/**\n * @brief Perform modular\
95+
\ exponentiation for 64-bit integers.\n * @tparam bit32 If true, won't use 128-bit\
96+
\ arithmetic. You should ensure that\n * all inputs are small enough to\
97+
\ avoid overflow (i.e. bit-32).\n * @param base The base number.\n * @param exponent\
98+
\ The exponent.\n * @param modulus The modulus.\n * @return (base^exponent) %\
99+
\ modulus\n */\ntemplate <bool bit32 = false>\nconstexpr uint64_t mod_pow(uint64_t\
100+
\ base, uint64_t exponent, uint64_t modulus) {\n uint64_t result = 1 % modulus;\n\
101+
\ base %= modulus;\n while (exponent > 0) {\n if (exponent & 1)\n result\
102+
\ = mod_mul<bit32>(result, base, modulus);\n base = mod_mul<bit32>(base, base,\
103+
\ modulus);\n exponent >>= 1;\n }\n return result;\n}\n\n/**\n * @brief Perform\
104+
\ modular exponentiation for 64-bit integers with a compile-time\n * modulus.\n\
105+
\ * @tparam Modulus The modulus.\n * @param base The base number.\n * @param exponent\
106+
\ The exponent.\n * @return (base^exponent) % Modulus\n */\ntemplate <uint64_t\
107+
\ Modulus>\nconstexpr uint64_t mod_pow(uint64_t base, uint64_t exponent) {\n \
108+
\ uint64_t result = 1 % Modulus;\n base %= Modulus;\n while (exponent > 0) {\n\
109+
\ if (exponent & 1)\n result = mod_mul<Modulus>(result, base);\n base\
110+
\ = mod_mul<Modulus>(base, base);\n exponent >>= 1;\n }\n return result;\n\
111+
}\n\n/**\n * @brief Compute the modular inverse of a 64-bit integer using Fermat's\
112+
\ Little\n * Theorem.\n * @tparam Modulus The modulus (must be prime).\n\
113+
\ * @param a The number to find the modular inverse of.\n * @return The modular\
114+
\ inverse of a modulo Modulus.\n */\ntemplate <uint64_t Modulus> constexpr uint64_t\
115+
\ mod_inv(uint64_t a) {\n return mod_pow<Modulus>(a, Modulus - 2);\n}\n\n/**\n\
116+
\ * @brief Compute the modular inverse of a compile-time 64-bit integer using\n\
117+
\ * Fermat's Little Theorem.\n * @tparam Modulus The modulus (must be prime).\n\
118+
\ * @tparam a The number to find the modular inverse of.\n * @return The modular\
119+
\ inverse of a modulo Modulus.\n */\ntemplate <uint64_t Modulus, uint64_t a> constexpr\
120+
\ uint64_t mod_inv() {\n return mod_pow<Modulus>(a, Modulus - 2);\n}\n} // namespace\
121+
\ weilycoder\n\n\n#line 1 \"weilycoder/number-theory/prime.hpp\"\n\n\n\n/**\n\
122+
\ * @file prime.hpp\n * @brief Prime Number Utilities\n */\n\n#line 11 \"weilycoder/number-theory/prime.hpp\"\
123+
\n#include <type_traits>\n\nnamespace weilycoder {\n/**\n * @brief Miller-Rabin\
124+
\ primality test for a given base.\n * @tparam bit32 If true, won't use 128-bit\
125+
\ arithmetic. You should ensure that\n * all inputs are small enough to\
126+
\ avoid overflow (i.e. bit-32).\n * @tparam base The base to test.\n * @param\
101127
\ n The number to test for primality.\n * @param d An odd component of n-1 (n-1\
102128
\ = d * 2^s).\n * @param s The exponent of 2 in the factorization of n-1.\n *\
103-
\ @return true if n is probably prime for all given bases, false if composite.\n\
104-
\ */\ntemplate <bool bit32, uint64_t base, uint64_t... Rest>\nconstexpr std::enable_if_t<(sizeof...(Rest)\
105-
\ != 0), bool>\nmiller_rabin_test(uint64_t n, uint64_t d, uint32_t s) {\n return\
106-
\ miller_rabin_test<bit32, base>(n, d, s) &&\n miller_rabin_test<bit32,\
107-
\ Rest...>(n, d, s);\n}\n\n/**\n * @brief Miller-Rabin primality test using multiple\
108-
\ bases.\n * @tparam bit32 If true, won't use 128-bit arithmetic. You should ensure\
109-
\ that\n * all inputs are small enough to avoid overflow (i.e. bit-32).\n\
110-
\ * @tparam bases The bases to test.\n * @param n The number to test for primality.\n\
111-
\ * @return true if n is probably prime, false if composite.\n */\ntemplate <bool\
129+
\ @return true if n is probably prime for the given base, false if composite.\n\
130+
\ */\ntemplate <bool bit32, uint64_t base>\nconstexpr bool miller_rabin_test(uint64_t\
131+
\ n, uint64_t d, uint32_t s) {\n uint64_t x = mod_pow<bit32>(base, d, n);\n \
132+
\ if (x == 0 || x == 1 || x == n - 1)\n return true;\n for (uint32_t r = 1;\
133+
\ r < s; ++r) {\n x = mod_mul<bit32>(x, x, n);\n if (x == n - 1)\n \
134+
\ return true;\n }\n return false;\n}\n\n/**\n * @brief Variadic template to\
135+
\ test multiple bases in Miller-Rabin test.\n * @tparam bit32 If true, won't use\
136+
\ 128-bit arithmetic. You should ensure that\n * all inputs are small\
137+
\ enough to avoid overflow (i.e. bit-32).\n * @tparam base The first base to test.\n\
138+
\ * @tparam Rest The remaining bases to test.\n * @param n The number to test\
139+
\ for primality.\n * @param d An odd component of n-1 (n-1 = d * 2^s).\n * @param\
140+
\ s The exponent of 2 in the factorization of n-1.\n * @return true if n is probably\
141+
\ prime for all given bases, false if composite.\n */\ntemplate <bool bit32, uint64_t\
142+
\ base, uint64_t... Rest>\nconstexpr std::enable_if_t<(sizeof...(Rest) != 0),\
143+
\ bool>\nmiller_rabin_test(uint64_t n, uint64_t d, uint32_t s) {\n return miller_rabin_test<bit32,\
144+
\ base>(n, d, s) &&\n miller_rabin_test<bit32, Rest...>(n, d, s);\n}\n\
145+
\n/**\n * @brief Miller-Rabin primality test using multiple bases.\n * @tparam\
146+
\ bit32 If true, won't use 128-bit arithmetic. You should ensure that\n * \
147+
\ all inputs are small enough to avoid overflow (i.e. bit-32).\n * @tparam\
148+
\ bases The bases to test.\n * @param n The number to test for primality.\n *\
149+
\ @return true if n is probably prime, false if composite.\n */\ntemplate <bool\
112150
\ bit32, uint64_t... bases> constexpr bool miller_rabin(uint64_t n) {\n if (n\
113151
\ < 2)\n return false;\n if (n == 2 || n == 3)\n return true;\n if (n\
114152
\ % 2 == 0)\n return false;\n\n uint64_t d = n - 1, s = 0;\n for (; d % 2\
@@ -201,7 +239,7 @@ data:
201239
isVerificationFile: true
202240
path: test/factorize.test.cpp
203241
requiredBy: []
204-
timestamp: '2025-11-07 09:14:02+08:00'
242+
timestamp: '2025-11-07 22:54:43+08:00'
205243
verificationStatus: TEST_ACCEPTED
206244
verifiedWith: []
207245
documentation_of: test/factorize.test.cpp

test/many_aplusb.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ data:
162162
isVerificationFile: true
163163
path: test/many_aplusb.test.cpp
164164
requiredBy: []
165-
timestamp: '2025-11-07 09:14:02+08:00'
165+
timestamp: '2025-11-07 22:54:43+08:00'
166166
verificationStatus: TEST_ACCEPTED
167167
verifiedWith: []
168168
documentation_of: test/many_aplusb.test.cpp

test/many_aplusb_128bit.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ data:
161161
isVerificationFile: true
162162
path: test/many_aplusb_128bit.test.cpp
163163
requiredBy: []
164-
timestamp: '2025-11-07 09:14:02+08:00'
164+
timestamp: '2025-11-07 22:54:43+08:00'
165165
verificationStatus: TEST_ACCEPTED
166166
verifiedWith: []
167167
documentation_of: test/many_aplusb_128bit.test.cpp

0 commit comments

Comments
 (0)