链接:https://www.nowcoder.com/acm/contest/144/C
来源:牛客网
题目描述
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 1 ≤ N ≤ 10 18 , 1 ≤ M ≤ 10 18 , )
输出描述:
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个集合进行n次操作,第i次操作都从第i个集合开始,每次操作可以向从i到n的集合中插入一个元素,元素范围为 1∼m 1 ∼ m ,n个集合为一个大集合,问你有多少个不同的大集合
我们以 n=4,m=4 n = 4 , m = 4 为例,先举一个 4,4 4 , 4 的两个集合
#include
#include
#include
#include
#include
using namespace std;
const long long mod=998244353;
const int N=1e6+5;
long long inv[N];
int main()
{
inv[0]=inv[1]=1;
for(int i=2; imod-mod/i)*inv[mod%i]%mod;
int t,cas=1;
scanf("%d",&t);
while(t--)
{
long long n,m;
scanf("%lld%lld",&n,&m);
long long ans=m%mod,sum=m%mod;
long long m_=m%mod,n_=n%mod;
for(int i=1; isum=sum*(m_-i)%mod*(n_-i)%mod*inv[i]%mod;
ans=(ans+sum)%mod;
}
printf("Case #%d: %lld\n",cas++,(ans+mod)%mod);
}
return 0;
}