QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#406252 | #8023. The Journey of Geor Autumn | Baiyu0123 | TL | 0ms | 0kb | C++14 | 600b | 2024-05-06 23:54:05 | 2024-05-06 23:54:05 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e7+100,mod=998244353;
int fac[maxn],inv[maxn],f[maxn];
int qpow(int x,int y) {
ll ret=1,bas=x;
while (y) {
if (y&1) ret=ret*bas%mod;
bas=bas*bas%mod;
y>>=1;
}
return ret;
}
int main() {
fac[0]=1;
for (int i=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
for (int i=1;i<maxn;i++) inv[i]=qpow(i,mod-2);
int n,k;
cin>>n>>k;
for (int i=1;i<=k;i++) f[i]=1;
for (int i=k+1,sum=k;i<=n;i++) {
f[i]=1ll*sum*inv[i]%mod;
sum=(0ll+sum+f[i]-f[i-k]+mod)%mod;
}
cout<<1ll*f[n]*fac[n]%mod;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
1 1