List’s father morejarphone likes playing poker with List very much. Now List has a deck of playing card, consisting of a black cards and b red cards. List shuffles the cards randomly, puts them on the desk and tells morejarphone to do the following operations:
taking away one card randomly;
checking the color of it, if it is black, repeats the operations until he take a red one or there are no cards left, else stops.
Now List wants to know the mathematical expectation of the cards morejarphone takes away in total. To avoid the float number, you should multiply the answer by (a+b)! then mod 1e9+7. If morejarphone can’t take red card, output “List, are you kidding me?”.
Input
The first of the input is an integer t (t<=100), which is the number of the cases.
Next t line, each line contains two numbers: a and b (1<=a+b<=1e6).
Output
For each case, output “Case #x: y”(without quota), where x is their number of the cases and y is the answer. If morejarphone can’t take red card, output “List, are you kidding me?”(without quota).
Sample Input
3
1 1
2 0
2 33
Sample Output
Case #1: 3
Case #2: List, are you kidding me?
Case #3: 15385176
计算公式,不难发现
ans=b∗(n−1)!+∑ai=0(i+2)∗a(a−1)..(a−i)b(n−i−2)!
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (1234567)
ll fact[MAXN];
int main() {
// freopen("A.in","r",stdin);
int T=read();
fact[0]=1; For(i,1e6) fact[i]=mul(fact[i-1],i);
For(kc,T) {
ll a=read(),b=read();
printf("Case #%d: ",kc);
if (!b) puts("List, are you kidding me?");
else {
ll t=b,ans=0,n=a+b;
Rep(i,a) {
t=mul(t,a-i);
upd(ans,mul(mul(t,fact[n-i-2]),i+2));
}
upd(ans,mul(b,fact[n-1]));
printf("%lld\n",ans);
}
}
return 0;
}