結果

問題 No.931 Multiplicative Convolution
ユーザー kwm_tkwm_t
提出日時 2023-06-11 15:46:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 2,137 bytes
コンパイル時間 4,285 ms
コンパイル使用メモリ 274,732 KB
実行使用メモリ 10,888 KB
最終ジャッジ日時 2023-08-31 01:57:49
合計ジャッジ時間 8,475 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 11 ms
4,376 KB
testcase_08 AC 124 ms
10,848 KB
testcase_09 AC 106 ms
10,680 KB
testcase_10 AC 114 ms
10,552 KB
testcase_11 AC 105 ms
10,404 KB
testcase_12 AC 83 ms
8,804 KB
testcase_13 AC 117 ms
10,576 KB
testcase_14 AC 133 ms
10,888 KB
testcase_15 AC 126 ms
10,804 KB
testcase_16 AC 120 ms
10,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0