标签:output pen exists image ace lease print sed 结果
Generation I
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.
2 2 2 3 4
Case #1: 4 Case #2: 52
#include <iostream> #define N 1000005 using namespace std; const long long mod=998244353; long long ny[N+5]; long long f(long long a,long long b) { long long ans=1; while(b>0) { if(b%2==1)ans=(ans*a)%mod; b/=2; a=(a*a)%mod; } return ans; } int main() { int t,tot=0; scanf("%d",&t); for(int i=1;i<=N;i++)ny[i]=f(i,mod-2); while(t--) { long long n,m,ans,upper,last; scanf("%lld %lld",&n,&m); upper=min(n,m); ans=last=m%mod; for(int i=2;i<=upper;i++) { last*=(m+1-i)%mod; last%=mod; last*=ny[i-1]; last%=mod; last*=(n+1-i)%mod; last%=mod; ans+=last; ans%=mod; } printf("Case #%d: %lld\n",++tot,ans); } return 0; }
标签:output pen exists image ace lease print sed 结果
原文地址:https://www.cnblogs.com/tian-luo/p/9419858.html