Gym - 101972I - Secret Project (组合数学 思维)

这篇博客探讨了一个涉及组合数学的问题,即如何通过分配钥匙和锁来确保至少有m名学生在场才能打开一个保密项目的柜子。题目描述了n名学生,每个学生持有y把独特的钥匙,每把钥匙对应一把锁。要求找到最小的锁数量x和每位学生至少需要携带的钥匙数量y,使得只有当m或更多学生在场时才能打开所有锁。博主提供了输入输出示例,并表示后续会补充题目分析。
摘要由CSDN通过智能技术生成

题目链接:

https://cn.vjudge.net/contest/275218#problem/I

题目:

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 个人,x把锁,(每个人有y把钥匙),要求最少有 m 个人在场才能打开这所有的x把锁,问 x y 的最小值分别是多少。(题目可能不好理解,看看Note和样例就明白了。)

题目分析:

有空再写,先空着~~~

代码:

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int MAXN = (int)1e5 + 100;
ll f[MAXN], r[MAXN];

ll qPow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = (ans * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return ans;
}

void Init() {
    f[0] = r[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        f[i] = (f[i - 1] * i) % MOD;
        r[i] = qPow(f[i], MOD - 2);
    }
}

inline ll GetC(ll n, ll m) { return ((f[n] * r[m]) % MOD) * r[n - m] % MOD; }

int main() {
    Init();
    int T;
    scanf("%d", &T);
    while (T--) {
        ll n, m;
        scanf("%lld %lld", &n, &m);
        printf("%lld %lld\n", GetC(n, m - 1), GetC(n - 1, m - 1));
    }
    return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值