Skip to content

Commit 3fcd51e

Browse files
authored
Merge pull request #142 from TumoiYorozu/Convolution_assert
add: assert of convolution
2 parents 118540c + f5c30a3 commit 3fcd51e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

atcoder/convolution.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ template <class mint, internal::is_static_modint_t<mint>* = nullptr>
199199
std::vector<mint> convolution_fft(std::vector<mint> a, std::vector<mint> b) {
200200
int n = int(a.size()), m = int(b.size());
201201
int z = 1 << internal::ceil_pow2(n + m - 1);
202+
assert(mint::mod() % z == 1);
202203
a.resize(z);
203204
internal::butterfly(a);
204205
b.resize(z);
@@ -274,6 +275,12 @@ std::vector<long long> convolution_ll(const std::vector<long long>& a,
274275
internal::inv_gcd(MOD1 * MOD3, MOD2).second;
275276
static constexpr unsigned long long i3 =
276277
internal::inv_gcd(MOD1 * MOD2, MOD3).second;
278+
279+
static constexpr int MAX_AB_BIT = 24;
280+
static_assert(MOD1 % (1ull << MAX_AB_BIT) == 1, "MOD1 isn't enough to support an array length of 2^24.");
281+
static_assert(MOD2 % (1ull << MAX_AB_BIT) == 1, "MOD2 isn't enough to support an array length of 2^24.");
282+
static_assert(MOD3 % (1ull << MAX_AB_BIT) == 1, "MOD3 isn't enough to support an array length of 2^24.");
283+
assert(a.size() + b.size() - 1 <= (1ull << MAX_AB_BIT));
277284

278285
auto c1 = convolution<MOD1>(a, b);
279286
auto c2 = convolution<MOD2>(a, b);

0 commit comments

Comments
 (0)