結果
問題 | No.2763 Macaron Gift Box |
ユーザー |
![]() |
提出日時 | 2024-05-17 22:44:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,848 ms / 3,000 ms |
コード長 | 5,536 bytes |
コンパイル時間 | 4,641 ms |
コンパイル使用メモリ | 269,080 KB |
最終ジャッジ日時 | 2025-02-21 15:10:21 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/all>using namespace std;using namespace atcoder;typedef int64_t ll;using mint=modint998244353;typedef long double ld;const ll MOD=1000000007;const ll MODA=998244353;ll vx[4]={0,1,0,-1};ll vy[4]={1,0,-1,0};#define rep(i,n) for(ll i=0;i<(ll)(n);i++)long long gcd(long long a,long long b){a=abs(a);b=abs(b);ll gcdmax=max(a,b);ll gcdmin=min(a,b);if(gcdmin==0)return gcdmax;while(true){if(gcdmax%gcdmin==0)break;else gcdmax%=gcdmin;swap(gcdmin,gcdmax);}return gcdmin;}ll pow(ll N,ll P,ll M){if(P==0)return 1;else if(P%2==0){ll t=pow(N,P/2,M);return t*t%M;}else return N*pow(N,P-1,M)%M;}ll pow(ll N,ll P){if(P==0)return 1;else if(P%2==0){ll t=pow(N,P/2);return t*t;}else return N*pow(N,P-1);}vector<ll> fac;vector<ll> finv;vector<ll> inv;void COMinit(ll N,ll P){rep(i,N+1){if(i==0){fac.push_back(1);finv.push_back(1);inv.push_back(1);}else if(i==1){fac.push_back(1);finv.push_back(1);inv.push_back(1);}else{fac.push_back(fac.at(i-1)*i%P);inv.push_back(P-inv.at(P%i)*(P/i)%P);finv.push_back(finv.at(i-1)*inv.at(i)%P);}}}ll COM(ll n,ll k,ll P){if(n<k)return 0;if(n<0||k<0)return 0;return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;}struct UnionFind {vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化for(ll i = 0; i < N; i++) par[i] = i;}ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}if (par[x] == x) return x;return par[x] = root(par[x]);}void unite(ll x, ll y) { // xとyの木を併合ll rx = root(x); //xの根をrxll ry = root(y); //yの根をryif (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのままpar[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける}bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返すll rx = root(x);ll ry = root(y);return rx == ry;}};struct My_FPS{vector<mint> f;ll deg;My_FPS(){f={};deg=0;}My_FPS(vector<mint> f_){f=f_;deg=f.size();}My_FPS(ll _deg){f.resize(_deg);deg=_deg;}void resize(ll n){f.resize(n);deg=n;}void multiply_sparse(ll n,ll a){for(ll i=deg-1;i>=n;i--)f[i]+=a*f[i-n];}void div_sparse(ll n,ll a){for(ll i=n;i<deg;i++)f[i]-=a*f[i-n];}My_FPS operator+(const My_FPS &other){My_FPS ret;ret.deg=max(deg,other.deg);ret.f.assign(ret.deg,0);rep(i,ret.deg){if(i<deg)ret.f[i]+=f[i];if(i<other.deg)ret.f[i]+=other.f[i];}return ret;}My_FPS operator-(const My_FPS &other){My_FPS ret;ret.deg=max(deg,other.deg);ret.f.assign(ret.deg,0);rep(i,ret.deg){if(i<deg)ret.f[i]+=f[i];if(i<other.deg)ret.f[i]-=other.f[i];}return ret;}My_FPS operator*(const My_FPS &other){My_FPS ret(convolution(f,other.f));return ret;}My_FPS operator*(const ll &n){My_FPS ret(deg);rep(i,deg){ret.f[i]=n*f[i];}return ret;}void operator=(const My_FPS &other){f=other.f;deg=other.deg;}};void fps_printline(My_FPS fx,ll s,ll t){for(ll i=s;i<t;i++)cout<<fx.f[i].val()<<endl;}void fps_printline_all(My_FPS fx){fps_printline(fx,0,fx.deg);}void fps_printspace(My_FPS fx,ll s,ll t){for(ll i=s;i<t;i++)cout<<fx.f[i].val()<<" ";cout<<endl;}void fps_printspace_all(My_FPS fx){fps_printspace(fx,0,fx.deg);}My_FPS fps_inv(My_FPS fx,ll n){My_FPS gp({1/fx.f[0]});ll sz=1;while(sz<n){gp=(gp+gp-(fx*gp)*gp);gp.resize(sz*2);sz*=2;}gp.resize(n);return gp;}My_FPS fps_integer(My_FPS fx){My_FPS ret(fx.deg+1);rep(i,fx.deg){ret.f[i+1]=fx.f[i]/(i+1);}return ret;}My_FPS fps_diff(My_FPS fx){My_FPS ret(fx.deg-1);rep(i,fx.deg){if(i>0)ret.f[i-1]=fx.f[i]*i;}return ret;}My_FPS fps_log(My_FPS fx,ll n){My_FPS ret=fps_integer(fps_diff(fx)*fps_inv(fx,n));ret.resize(n);return ret;}My_FPS fps_exp(My_FPS fx,ll n){My_FPS gp((vector<mint>){1});ll sz=1;while(sz<n){gp=gp-gp*fps_log(gp,sz*2)+gp*fx;sz*=2;gp.resize(sz);}gp.resize(n);return gp;}My_FPS fps_pow(My_FPS fx,ll p,ll n){My_FPS logf=fps_log(fx,2*n);return fps_exp(logf*p,n);}int main(){ll N,K;cin>>N>>K;My_FPS f(N+1);for(ll i=1;i<=N;i++){for(ll j=1;i*j*(K+1)<=N;j++){f.f[i*j*(K+1)]-=(mint)1/(mint)j;}}for(ll i=1;i<=N;i++){for(ll j=1;i*j<=N;j++){f.f[i*j]+=(mint)1/(mint)j;}}My_FPS Ans=fps_exp(f,N+1);rep(i,N+1){if(i>0)cout<<Ans.f[i].val()<<" ";}cout<<endl;}