CF2184D.Unfair Game

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Bob is tired of losing to Alice and, to ensure he doesn't lose again, decided to choose a game in which he is guaranteed to win. Bob has thought of a number from 11 to nn, where it is known that n=2dn = 2^d for some non-negative integer dd. Initially, Alice knows whether the chosen number is even or not.

In one move, Alice can either halve the number or subtract 11. Alice can only halve the number if the current number is even. Only Alice takes turns.

After her move, Alice receives a response from Bob: either −1-1, which means the number has become 00 and Alice has won, or a non-negative integer xx. If we denote the current number as aa, then for xx the following conditions hold simultaneously:

  1. aa is divisible by 2x2^x.
  2. aa is not divisible by 2x+12^{x+1}.

For example, if a=5a=5, then x=0x=0, since 55 is divisible by 20=12^0=1 and not divisible by 21=22^1=2, and if a=12a=12, then x=2x=2, since 1212 is divisible by 22=42^2=4 and not divisible by 23=82^3=8.

It can be shown that for any integer a>0a \gt 0, there exists a unique such xx.

Bob is still afraid that Alice will win, so the game will have no more than kk moves. Additionally, Bob wants to maximize his chances of winning, so he wants to play as many games as possible. Given nn and kk, calculate the number of initial numbers from 11 to nn such that Alice, playing optimally, cannot win in no more than kk moves.

鲍勃厌倦了输给爱丽丝,为了确保自己不再输,他决定选择一个自己必胜的游戏。鲍勃从 11 到 nn 之间想好了一个数,其中已知 n=2dn = 2^d(dd 为某个非负整数)。初始时,爱丽丝知道该数是偶数还是奇数。

在一次操作中,爱丽丝可以执行以下两种操作之一:将当前数减半,或减 11。她仅当当前数为偶数时才能执行减半操作。只有爱丽丝进行操作。

每次操作后,鲍勃会向爱丽丝返回一个响应:要么是 −1-1,表示该数已变为 00,爱丽丝获胜;要么是一个非负整数 xx。若记当前数为 aa,则 xx 同时满足以下两个条件:

  1. aa 能被 2x2^x 整除;
  2. aa 不能被 2x+12^{x+1} 整除。

例如,若 a=5a=5,则 x=0x=0,因为 55 可被 20=12^0 = 1 整除,但不可被 21=22^1 = 2 整除;若 a=12a=12,则 x=2x=2,因为 1212 可被 22=42^2 = 4 整除,但不可被 23=82^3 = 8 整除。

可以证明:对任意正整数 aa,均存在唯一满足上述条件的 xx。

鲍勃仍担心爱丽丝获胜,因此游戏最多进行 kk 步。此外,鲍勃希望最大化自己的胜率,即尽可能多地进行游戏。给定 nn 和 kk,请计算在 11 到 nn 的初始数字中,有多少个数使得爱丽丝即使采取最优策略,也无法在至多 kk 步内获胜。

输入格式

The first line contains an integer tt (1≤t≤104)(1 \le t \le 10^4) — the number of test cases.

The only line of each test case contains 22 integers nn and kk (1≤n,k≤109)(1 \le n, k \le 10^9) — the limit on the chosen number and the maximum number of Alice's moves, respectively. It is guaranteed that n=2dn = 2^d for some non-negative integer dd.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例仅一行,包含两个整数 nn 和 kk(1≤n,k≤1091 \le n, k \le 10^9)—— 分别为所选数字的上限以及 Alice 的最大移动次数。保证 n=2dn = 2^d,其中 dd 为某个非负整数。

输出格式

For each test case, output the number of integers from 11 to nn such that Alice, playing optimally, cannot win in at most kk moves.

对于每个测试用例,输出从 11 到 nn 中满足以下条件的整数个数:Alice 以最优策略进行游戏时,无法在至多 kk 步内获胜。

输入输出样例

  • 输入#1

    7
    4 1
    4 2
    4 3
    4 4
    4 5
    16 5
    16 1

    输出#1

    3
    2
    0
    0
    0
    4
    15

说明/提示

In the first sample, a=2a=2, a=3a=3, and a=4a=4 are suitable because from a=1a=1 one can reach 00 in 11 operation, while for the other values, it can be shown that at least 22 operations are required.

In the second sample, a=3a=3 and a=4a=4 are suitable because for a=2a=2, Alice can win in 22 operations.

In the third, fourth, and fifth samples, there are no suitable aa, because for a=3a=3 and a=4a=4, Alice can win in 33 operations.

在第一个样例中,a=2a=2、a=3a=3 和 a=4a=4 是合适的,因为从 a=1a=1 出发可在 11 步操作内到达 00,而对其他取值,可以证明至少需要 22 步操作。

在第二个样例中,a=3a=3 和 a=4a=4 是合适的,因为当 a=2a=2 时,Alice 可在 22 步操作内获胜。

在第三、第四和第五个样例中,不存在合适的 aa,因为当 a=3a=3 和 a=4a=4 时,Alice 均可在 33 步操作内获胜。

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

首页