NC214892. TheJourneyofGeorAutumn
描述
输入描述
The first line contains two integers n and k separated by a single space (, ).
输出描述
Output only one integer in one line---the number of good poems modulo .
示例1
输入:
1 1
输出:
1
示例2
输入:
2 3
输出:
2
示例3
输入:
3 2
输出:
4
示例4
输入:
4 2
输出:
10
C++(clang++11) 解法, 执行用时: 392ms, 内存消耗: 156920K, 提交时间: 2021-01-26 16:47:19
#include<bits/stdc++.h> #define ll long long using namespace std; const int mod=998244353; const int maxn=1e7+10; ll inv[maxn],p[maxn]; int n,k; int main(){ inv[1]=1; for(int i=2;i<maxn;i++) inv[i]=mod-mod/i*inv[mod%i]%mod; scanf("%d%d",&n,&k); ll s=p[0]=1; for(int i=1;i<=n;i++){ p[i]=inv[i]*s%mod; s+=p[i]; if(i>=k) s-=p[i-k]; s%=mod; } ll ans=p[n]%mod+mod; for(int i=1;i<=n;i++) ans=ans*i%mod; printf("%lld",ans); }