记录编号 583536 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 Maximized Combos 最终得分 100
用户昵称 GravatarHzmQwQ 是否通过 通过
代码语言 C++ 运行时间 0.647 s
提交时间 2023-10-18 15:30:02 内存使用 5.03 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define MAXN 200005

using namespace std;

typedef long long ll;

const ll M = 998244353LL;
int n, m;
ll fac[MAXN], pfac[MAXN], pinvfac[MAXN], invfac[MAXN], co1[MAXN];

ll quick_pow(ll base, ll xp) {
    ll ret = 1LL;
    while(xp > 0) {
        if(xp & 1LL) ret = (ret * base) % M;
        base = (base * base) % M;
        xp >>= 1LL;
    }
    return ret;
}

void init() {
    fac[0] = pfac[0] = pinvfac[0] = invfac[0] = 1;
    for(int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * (ll)i) % M;
    for(int i = 1; i <= n; i++) pfac[i] = (pfac[i - 1] * fac[i]) % M;
    pinvfac[n] = quick_pow(pfac[n], M - 2LL);
    for(int i = n - 1; i >= 1; i--) pinvfac[i] = (pinvfac[i + 1] * fac[i + 1]) % M;
    for(int i = 1; i <= n; i++) invfac[i] = (pinvfac[i] * pfac[i - 1]) % M;
    return ;
}

ll Comb(ll fr, ll ch) {
    if(fr < ch) return 0LL;
    return (fac[fr] * invfac[fr - ch] % M) * invfac[ch] % M;
}

ll solve(int s) {
    ll ret = 0LL;
    for(int i = 1; i <= n - m + 1 && i * s <= m; i++) {
        ll dec = (Comb(n - i * s, n - m) - Comb(n - i * s - i, n - m) + M) % M;
        if(i & 1) ret = (ret + (co1[i] * dec % M)) % M;
        else ret = (ret - (co1[i] * dec % M) + M) % M;
    }
    return ret;
}

int main() {
    freopen("combos.in", "r", stdin);
    freopen("combos.out", "w", stdout);
    scanf("%d %d", &n, &m);
    init();
    for(int i = 1; i <= n - m + 1; i++) co1[i] = Comb(n - m + 1, i);
    for(int i = 1; i <= m; i++) printf("%lld\n", solve(i));
    return 0;
}