結果
| 問題 |
No.931 Multiplicative Convolution
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2023-06-11 15:46:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 156 ms / 2,000 ms |
| コード長 | 2,137 bytes |
| コンパイル時間 | 4,600 ms |
| コンパイル使用メモリ | 265,488 KB |
| 最終ジャッジ日時 | 2025-02-14 01:50:28 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int calc_primitive_root(int p) {
if (p == 2) return 1;
if (p == 167772161) return 3;
if (p == 469762049) return 3;
if (p == 754974721) return 11;
if (p == 998244353) return 3;
// p-1 の素因数分解
int divs[20] = {};
divs[0] = 2;
int cnt = 1;
long long x = (p - 1) / 2;
while (x % 2 == 0) x /= 2;
for (long long i = 3; i * i <= x; i += 2) {
if (x % i == 0) {
divs[cnt++] = i;
while (x % i == 0) x /= i;
}
}
if (x > 1) divs[cnt++] = x;
// 原始根であるかの判定のために root^((p-1)/d) != 1 (mod p) を確かめる
for (int root = 2;; ++root) {
bool ok = true;
for (int i = 0; i < cnt; ++i) {
if (pow_mod(root, (p - 1) / divs[i], p) == 1) {
ok = false;
break;
}
}
if (ok) return root;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
map<int, int>mp;
int p; cin >> p;
int root = calc_primitive_root(p);
rep(i, p - 1) {
int x = pow_mod(root, i, p);
mp[x] = i;
}
vector<mint>a(p), b(p);
rep(i, p - 1) {
int x; cin >> x;
a[mp[i + 1]] += x;
}
rep(i, p - 1) {
int x; cin >> x;
b[mp[i + 1]] += x;
}
auto c = convolution(a, b);
vector<mint>ans(p);
rep(i, c.size()) {
int x = pow_mod(root, i, p);
ans[x] += c[i];
}
rep2(i, 1, ans.size())cout << ans[i].val() << " ";
cout << endl;
return 0;
}
kwm_t