1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include<bits/stdc++.h> #define inf 0x3f3f3f3f3f3f3f3fll #define debug(x) cerr<<#x<<"="<<x<<endl using namespace std; using ll=long long; using ld=long double; using pli=pair<ll,int>; using pi=pair<int,int>; template<typename A> using vc=vector<A>; inline int read() { int s=0,w=1;char ch; while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1; while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } inline ll lread() { ll s=0,w=1;char ch; while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1; while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } const int mod=998244353; ll pre[10000005]; ll inv[10000005]; ll jc[10000005]; int n,m; inline ll qow(ll a,ll b) { ll ans=1; while(b) { if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans; } inline void init(int L) { jc[0]=1; for(int i=1;i<=L;i++) jc[i]=jc[i-1]*i%mod; inv[L]=qow(jc[L],mod-2); for(int i=L;i;i--) inv[i-1]=inv[i]*i%mod; } inline ll C(int a,int b) { return jc[a]*inv[b]%mod*inv[a-b]%mod; } inline ll get(int L,int R) { if(L<0&&R>0) return get(0,R)+get(1,-L); if(L<0) swap(L,R),L=-L,R=-R; ll ans=pre[R]; if(L) ans-=pre[L-1]; return ans; } inline ll get(int w) { int L=max(1-n,0-w); int R=min(n-1,m-w); if(L>R) return 0; return get(L,R); } int main() { n=read(),m=(read()+1)/2;init(n-1); for(int i=0;i<n;i++) { if(i) pre[i]=pre[i-1]; if((n-1-i)%2==0) pre[i]=(pre[i]+C(n-1,(n-1+i)>>1))%mod; } ll ans=get(1);int w1=1,w2=1; for(int i=0;i<=(n+m-1)/m;i++) { swap(w1,w2); w1=-2-w1,w2=2*(m+1)-w2; if(i&1) ans+=get(w1)+get(w2); else ans-=get(w1)+get(w2); } ans=(ans%mod+mod)%mod; printf("%lld\n",ans); return 0; }
|