A11196 | El Toll Caves
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The prehistoric caves of El Toll are located in Moià (Barcelona). You have heard that there is a treasure hidden in one of $n$ possible spots in the caves. You assume that each of the spots has probability $1/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 $k$ 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/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 $x$ times is $1/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 $10^{9}+7$ . Formally, let the answer be an irreducible fraction $P/Q$ , then you have to output . It is guaranteed that $Q$ is not divisible by $10^{9}+7$ .
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 $k$ 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/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 $x$ times is $1/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 $10^{9}+7$ . Formally, let the answer be an irreducible fraction $P/Q$ , then you have to output . It is guaranteed that $Q$ is not divisible by $10^{9}+7$ .
输入格式
The first line contains the number of test cases $T$ ( $1<=T<=1000$ ).
Each of the next $T$ lines contains two integers $n$ and $k$ ( $1<=k<=n<=5·10^{8}$ ).
Each of the next $T$ lines contains two integers $n$ and $k$ ( $1<=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/2$ if we search the two spots alternatively. In the third case the answer is $25/9$ .
In the second case the answer can be shown to be equal to $7/2$ if we search the two spots alternatively. In the third case the answer is $25/9$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted