File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ // @brief Convolution on the Multiplicative Monoid of $\mathbb Z/p\mathbb{Z}$
2
+ #define PROBLEM " https://judge.yosupo.jp/problem/mul_modp_convolution"
3
+ #pragma GCC optimize("Ofast,unroll-loops")
4
+ #define CP_ALGO_CHECKPOINT
5
+ #include < bits/stdc++.h>
6
+ #include " blazingio/blazingio.min.hpp"
7
+ #include " cp-algo/number_theory/euler.hpp"
8
+ #include " cp-algo/math/fft.hpp"
9
+
10
+ using namespace std ;
11
+
12
+ using base = cp_algo::math::modint<998244353 >;
13
+
14
+ void solve () {
15
+ int p;
16
+ cin >> p;
17
+ auto g = cp_algo::math::primitive_root (p);
18
+ vector<int > lg (p);
19
+ int64_t cur = 1 ;
20
+ for (int i = 0 ; i < p - 1 ; i++) {
21
+ lg[cur] = i;
22
+ cur *= g;
23
+ cur %= p;
24
+ }
25
+ base a0, b0, as = 0 , bs = 0 ;
26
+ vector<base> a (p-1 ), b (p-1 );
27
+ cin >> a0;
28
+ for (int i = 1 ; i <= p - 1 ; i++) {
29
+ cin >> a[lg[i]];
30
+ as += a[lg[i]];
31
+ }
32
+ cin >> b0;
33
+ for (int i = 1 ; i <= p - 1 ; i++) {
34
+ cin >> b[lg[i]];
35
+ bs += b[lg[i]];
36
+ }
37
+ base c0 = (a0 + as) * (b0 + bs) - as * bs;
38
+ cout << c0 << " " ;
39
+ cp_algo::math::fft::mul (a, b);
40
+ for (size_t i = p-1 ; i < size (a); i++) {
41
+ a[i - (p-1 )] += a[i];
42
+ }
43
+ for (int i = 1 ; i <= p - 1 ; i++) {
44
+ cout << a[lg[i]] << " " ;
45
+ }
46
+ }
47
+
48
+ signed main () {
49
+ // freopen("input.txt", "r", stdin);
50
+ ios::sync_with_stdio (0 );
51
+ cin.tie (0 );
52
+ solve ();
53
+ }
You can’t perform that action at this time.
0 commit comments