CF439E.Devu and Birthday Celebration

提高+/省选-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend to be sad, so he would ensure to give at least one sweet to each friend.

He wants to celebrate it in a unique style, so he would like to ensure following condition for the distribution of sweets. Assume that he has distributed n sweets to his friends such that i__th friend is given a__i sweets. He wants to make sure that there should not be any positive integer x > 1, which divides every a__i.

Please find the number of ways he can distribute sweets to his friends in the required way. Note that the order of distribution is important, for example [1, 2] and [2, 1] are distinct distributions. As the answer could be very large, output answer modulo 1000000007 (109 + 7).

To make the problem more interesting, you are given q queries. Each query contains an n, f pair. For each query please output the required number of ways modulo 1000000007 (109 + 7).

今天是 Devu 的生日。为了庆祝这一时刻,他从附近的市场买了 nn 颗糖果。他邀请了 ff 位朋友,并希望将这些糖果分发给他们。由于他是一位善良的人,且这是一个特别的日子,他不希望任何一位朋友感到难过,因此他要确保每位朋友至少得到一颗糖果。

他希望以一种独特的方式庆祝,因此他要求糖果的分发满足以下条件:假设他将 nn 颗糖果分发给了朋友们,其中第 ii 位朋友得到 aia_i 颗糖果,则他要求:不存在任一正整数 x>1x > 1,使得 xx 能整除每一个 aia_i。

请计算他按上述要求分发糖果的方案总数。注意:分发顺序是重要的,例如 [1,2][1, 2] 和 [2,1][2, 1] 被视为两种不同的分发方式。由于答案可能非常大,请对 10000000071000000007(即 109+710^9 + 7)取模后输出。

为了让问题更有趣,你将收到 qq 个查询。每个查询包含一对 (n,f)(n, f)。对每个查询,请输出满足要求的分发方案数对 10000000071000000007(即 109+710^9 + 7)取模的结果。

输入格式

The first line contains an integer q representing the number of queries (1 ≤ q ≤ 105). Each of the next q lines contains two space space-separated integers n, f (1 ≤ f ≤ n ≤ 105).

第一行包含一个整数 qq,表示查询次数(1 ≤ q ≤ 1051 \le q \le 10^5)。接下来的 qq 行中,每行包含两个用空格分隔的整数 nn、ff(1 ≤ f ≤ n ≤ 1051 \le f \le n \le 10^5)。

输出格式

For each query, output a single integer in a line corresponding to the answer of each query.

对于每个查询,在一行中输出一个整数,对应于该查询的答案。

输入输出样例

  • 输入#1

    5
    6 2
    7 2
    6 3
    6 4
    7 4

    输出#1

    2
    6
    9
    10
    20

说明/提示

For first query: n = 6, f = 2. Possible partitions are [1, 5] and [5, 1].

For second query: n = 7, f = 2. Possible partitions are [1, 6] and [2, 5] and [3, 4] and [4, 3] and [5, 3] and [6, 1]. So in total there are 6 possible ways of partitioning.

第一次查询:n=6, f=2n = 6,\ f = 2。可能的划分为 [1,5][1, 5] 和 [5,1][5, 1]。

第二次查询:n=7, f=2n = 7,\ f = 2。可能的划分为 [1,6][1, 6]、[2,5][2, 5]、[3,4][3, 4]、[4,3][4, 3]、[5,3][5, 3] 和 [6,1][6, 1]。因此,总共有 6 种可能的划分方式。

输入解题思路,AI测评打分。不知道怎么写?

首页