101775A Chat Group
It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: since every 3 or more persons could make a chat group, there can be 42 different chat groups.
Given N persons in a dormitory, and every K or more persons could make a chat group, how many different chat groups could there be?
Input
The input starts with one line containing exactly one integer T which is the number of test cases.
Each test case contains one line with two integers N and K indicating the number of persons in a dormitory and the minimum number of persons that could make a chat group.
1 ≤ T ≤ 100.
1 ≤ N ≤ 109.
3 ≤ K ≤ 105.
Output
For each test case, output one line containing “Case #x: y” where x is the test case number (starting from 1) and y is the number of different chat groups modulo 1000000007.
Example
Input
1
6 3
Output
Case #1: 42
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+7;
const ll mod=1e9+7;
ll quick(ll a, ll b)
{
ll ans=1;
a%=mod;
while(b)
{
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod ;
}
return ans;
}
int main()
{
int t;
cin>>t;
for(int cas=1;cas<=t;cas++)
{
ll n,k,ans=0;
scanf("%lld%lld",&n,&k);
ans=quick(2,n)-1;
ll tmp=n;
for(ll i=1;i<k;i++)
{
ans=(ans+mod-tmp)%mod;
tmp=tmp*(n-i)%mod;
tmp=tmp*quick(i+1,mod-2)%mod;
}
printf("Case #%d: %lld\n",cas,ans);
}
}