CF868G.El Toll Caves

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The prehistoric caves of El Toll are located in Moià (Barcelona). You have heard that there is a treasure hidden in one of nn possible spots in the caves. You assume that each of the spots has probability 1/n1/n to contain a treasure.

You cannot get into the caves yourself, so you have constructed a robot that can search the caves for treasure. Each day you can instruct the robot to visit exactly kk distinct spots in the caves. If none of these spots contain treasure, then the robot will obviously return with empty hands. However, the caves are dark, and the robot may miss the treasure even when visiting the right spot. Formally, if one of the visited spots does contain a treasure, the robot will obtain it with probability 1/21/2 , otherwise it will return empty. Each time the robot searches the spot with the treasure, his success probability is independent of all previous tries (that is, the probability to miss the treasure after searching the right spot xx times is 1/2x1/2^{x} ).

What is the expected number of days it will take to obtain the treasure if you choose optimal scheduling for the robot? Output the answer as a rational number modulo 109+710^{9}+7 . Formally, let the answer be an irreducible fraction P/QP/Q , then you have to output . It is guaranteed that QQ is not divisible by 109+710^{9}+7 .

输入格式

The first line contains the number of test cases TT ( 1<=T<=10001<=T<=1000 ).

Each of the next TT lines contains two integers nn and kk ( 1<=k<=n<=51081<=k<=n<=5·10^{8} ).

输出格式

For each test case output the answer in a separate line.

输入输出样例

  • 输入#1

    3
    1 1
    2 1
    3 2
    

    输出#1

    2
    500000007
    777777786
    

说明/提示

In the first case the robot will repeatedly search in the only spot. The expected number of days in this case is 2. Note that in spite of the fact that we know the treasure spot from the start, the robot still has to search there until he succesfully recovers the treasure.

In the second case the answer can be shown to be equal to 7/27/2 if we search the two spots alternatively. In the third case the answer is 25/925/9 .

首页