牛客多校第六场 --- C Generation I

链接:https://www.nowcoder.com/acm/contest/144/C
来源:牛客网

Generation I
时间限制:C/C++ 3秒,其他语言6秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
Oak is given N empty and non-repeatable sets which are numbered from 1 to N.

Now Oak is going to do N operations. In the i-th operation, he will insert an integer x between 1 and M to every set indexed between i and N.

Oak wonders how many different results he can make after the N operations. Two results are different if and only if there exists a set in one result different from the set with the same index in another result.

Please help Oak calculate the answer. As the answer can be extremely large, output it modulo 998244353.
输入描述:
The input starts with one line containing exactly one integer T which is the number of test cases. (1 ≤ T ≤ 20)

Each test case contains one line with two integers N and M indicating the number of sets and the range of integers. (1 ≤ N ≤ 1018, 1 ≤ M ≤ 1018, )
输出描述:
For each test case, output “Case #x: y” in one line (without quotes), where x is the test case number (starting from 1) and y is the number of different results modulo 998244353.
示例1
输入
复制
2
2 2
3 4
输出
复制
Case #1: 4
Case #2: 52

这里写图片描述
隔板法相当于是把n个位置分为k组

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int mod = 998244353;
LL n,m;
LL inv[N];

//线性处理逆元
void init()
{
    inv[0] = 1;inv[1] = 1;
    for(int i = 2;i < N;++i)
    {
        inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    }
}

int main()
{
    int t;
    scanf("%d",&t);
    init();
    int p = 0;
    while(t--)
    {
        scanf("%lld %lld",&n,&m);
        p++;
        LL x = min(n,m);
        LL prem = m % mod;
        LL prec = 1;
        LL ans = prem * prec;
        for(LL i = 2;i <= x;++i)
        {
            prem = prem * (m % mod - i + 1) % mod;
            prec = prec * (n % mod - i + 1) % mod * inv[i - 1] % mod;
            ans = (ans + prec * prem % mod) % mod;
        }
        printf("Case #%d: %lld\n",p,ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值