結果

問題 No.3414 Aperiodic Sequence
コンテスト
ユーザー shobonvip
提出日時 2025-12-26 17:14:29
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 365 ms / 3,000 ms
コード長 3,031 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,246 ms
コンパイル使用メモリ 264,212 KB
実行使用メモリ 10,664 KB
最終ジャッジ日時 2025-12-26 17:14:39
合計ジャッジ時間 8,966 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/**
	author:  shobonvip
	created: 2025.12.26 17:07:07
**/

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

// Inv of Polynomial
// O(N log N)
// T should be modint
template<typename T>
std::vector<T> poly_inv(std::vector<T> &a, int M = -314159265){
	if (M == -314159265) M = (int)a.size();
	else if (M <= 0) return {};
	int n = a.size();
	T r = a[0].pow(T::mod()-2);
	int m = 1;
	std::vector<T> res = {r};
	while (m < M){
		std::vector<T> f = a;
		f.resize(std::min(n, 2*m));
		std::vector<T> h = atcoder::convolution(f, res);
		for (int i=0; i<std::min(2*m, (int)h.size()); i++){
			h[i] = -h[i];
		}
		h[0] += 2;
		h.resize(2*m);
		h = atcoder::convolution(h, res);
		h.resize(2*m);
		swap(res, h);
		m <<= 1;
	}
	res.resize(M);
	return res;
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m; cin >> n >> m;
	vector<mint> v(n);
	rep(i,0,n) {
		int x; cin >> x;
		v[i] = x;
	}

	vector<bool> p(m + 1);
	vector<mint> mu(m + 1, 1);
	for (int i=2; i<=m; i++) {
		if (p[i]) continue;
		for(int j=i; j<=m; j+=i) {
			p[j] = 1;
			if(j/i%i==0) mu[j] = 0;
			mu[j] *= -1;
		}
	}

	auto calc = [&](auto self, int l, int r)
	-> pair<vector<mint>,vector<mint>> {
		if (l + 1 == r) {
			vector<mint> si(1, 1);
			vector<mint> bo(2, 1);
			bo[1] = -v[l];
			return pair(si, bo);
		}
		int m = (l + r) / 2;
		auto [si1, bo1] = self(self, l, m);
		auto [si2, bo2] = self(self, m, r);
		vector<mint> sit1 = convolution(si1, bo2);
		vector<mint> sit2 = convolution(si2, bo1);
		vector<mint> si(max((int)sit1.size(), (int)sit2.size()));
		rep(i,0,(int)sit1.size()) si[i] += sit1[i];
		rep(i,0,(int)sit2.size()) si[i] += sit2[i];
		vector<mint> bo = convolution(bo1, bo2);
		return pair(si, bo);
	};

	auto [si, bo] = calc(calc, 0, n);
	vector<mint> f = convolution(si, poly_inv(bo, m+1));
	
	vector<mint> ans(m + 1);
	rep(i,1,m+1) {
		mint tmp = mu[i];
		for (int j=i; j<=m; j+=i) {
			tmp *= f[i];
			ans[j] += tmp;
		}
	}

	rep(i,1,m+1) {
		cout << ans[i].val() << ' ';
	}
	cout << '\n';

}

0