Gym - 101972I Secret Project 组合数+思维

26 篇文章 0 订阅
21 篇文章 0 订阅

There are n students working on a secret project, this project is very important and unique, so they decided to keep it safe, and protect it from leakage.

The students will put all the project's documents in a cabinet that has x locks, and each student will take a set of y unique keys, such that each key can open only one lock. The cabinet can be opened if and only if m or more of the students are present.

Each of the cabinet's lock has an infinite number of keys that can open it, and students may have different or similar sets of keys. In order to open the cabinet, zstudents must be presented (m ≤ z), such that these students have at least one key for each cabinet's lock.

Your task is to find minimum values of x and y. More formally, your task is to find what is the minimum number of locks needed and what is the minimum number of keys to the locks each student must carry such that the cabinet can be opened if and only if m or more of the students are present. Since these numbers are large, you need to print them modulo 109 + 7.

Input

The first line contains an integer T (1 ≤ T ≤ 105) specifying the number of test cases.

Each test case consists of a single line containing two integers n and m (1 ≤ m ≤ n ≤ 105), in which n is the number of students, and m is the minimum number of students that must be present to open the cabinet.

Output

For each test case, print a single line containing two integers x and y, in which xis the smallest number of locks needed, and y is the smallest number of keys to the locks each student must carry. Both numbers must be printed modulo 109 + 7.

Example

Input

4
3 2
2 2
5 4
5 3

Output

3 2
2 1
10 4
10 6

Note

In the first test case, there are 3 students, and at least 2 of them must present to open the cabinet. The optimal answer is to use 3 locks for the cabinet, such that each student will take 2 keys as follow: the 1st student takes keys of the 1st and 2nd locks, the 2nd student takes keys of the 1st and 3rd locks, and the 3rd student takes keys of the 2nd and 3rd locks. This distribution will ensure that at least two students must present in order to unlock all locks and open the cabinet.

题意:有一个重要的基地,该基地有n个人,为了防止泄密,要求给基地上锁,希望:门能打开当且仅当有至少m个人来到基地,求至少需要几把锁,每个人至少需要几把钥匙。

题解:做的时候写了计算了几个数,找到了规律,锁C[n][m-1]  钥匙C[n - 1][m - 1]

这个讲的比较清楚:点击查看

这里用到了求组合数,推荐看一下关于组合数的知识:点击查看

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+100;
typedef long long ll;
const ll mod=1e9+7;
ll n,m;
ll ni[N],fi[N];
ll ksm(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ans;
}
void init()
{
	fi[0]=1;
	fi[1]=1;
	for(int i=2;i<=100000;i++)
		fi[i]=(fi[i-1]*i)%mod;
	ni[0]=1;
	for(int i=1;i<=100000;i++)
	{
		ni[i]=ksm(fi[i],mod-2);
	}
}
int main()
{
	int t;
	init();
	scanf("%d",&t);
	
	while(t--)
	{
		scanf("%lld%lld",&n,&m);
		printf("%lld %lld\n",(fi[n]*ni[m-1]%mod)*ni[n-m+1]%mod,(fi[n-1]*ni[m-1]%mod)*ni[n-1-m+1]%mod);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值