CF2029A.Set

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Set

You are given a positive integer kk and a set SS of all integers from ll to rr (inclusive).

You can perform the following two-step operation any number of times (possibly zero):

  1. First, choose a number xx from the set SS, such that there are at least kk multiples of xx in SS (including xx itself);
  2. Then, remove xx from SS (note that nothing else is removed).

Find the maximum possible number of operations that can be performed.

Input

Each test contains multiple test cases. The first line of the input contains a single integer tt (1t1041\le t\le 10^4) — the number of test cases. The description of test cases follows.

The only line of each test case contains three integers ll, rr, and kk (1lr1091\le l\le r\leq 10^9, 1krl+11\leq k\le r-l+1) — the minimum integer in SS, the maximum integer in SS, and the parameter kk.

Output

For each test case, output a single integer — the maximum possible number of operations that can be performed.

Note

In the first test case, initially, S={3,4,5,6,7,8,9}S = \{3,4,5,6,7,8,9\}. One possible optimal sequence of operations is:

  1. Choose x=4x = 4 for the first operation, since there are two multiples of 44 in SS: 44 and 88. SS becomes equal to {3,5,6,7,8,9}\{3,5,6,7,8,9\};
  2. Choose x=3x = 3 for the second operation, since there are three multiples of 33 in SS: 33, 66, and 99. SS becomes equal to {5,6,7,8,9}\{5,6,7,8,9\}.

In the second test case, initially, S={4,5,6,7,8,9}S=\{4,5,6,7,8,9\}. One possible optimal sequence of operations is:

  1. Choose x=5x = 5, SS becomes equal to {4,6,7,8,9}\{4,6,7,8,9\};
  2. Choose x=6x = 6, SS becomes equal to {4,7,8,9}\{4,7,8,9\};
  3. Choose x=4x = 4, SS becomes equal to {7,8,9}\{7,8,9\};
  4. Choose x=8x = 8, SS becomes equal to {7,9}\{7,9\};
  5. Choose x=7x = 7, SS becomes equal to {9}\{9\};
  6. Choose x=9x = 9, SS becomes equal to {}\{\}.

In the third test case, initially, S={7,8,9}S=\{7,8,9\}. For each xx in SS, no multiple of xx other than xx itself can be found in SS. Since k=2k = 2, you can perform no operations.

In the fourth test case, initially, S={2,3,4,5,6,7,8,9,10}S=\{2,3,4,5,6,7,8,9,10\}. One possible optimal sequence of operations is:

  1. Choose x=2x = 2, SS becomes equal to {3,4,5,6,7,8,9,10}\{3,4,5,6,7,8,9,10\};
  2. Choose x=4x = 4, SS becomes equal to {3,5,6,7,8,9,10}\{3,5,6,7,8,9,10\};
  3. Choose x=3x = 3, SS becomes equal to {5,6,7,8,9,10}\{5,6,7,8,9,10\};
  4. Choose x=5x = 5, SS becomes equal to {6,7,8,9,10}\{6,7,8,9,10\}.

Samples

8
3 9 2
4 9 1
7 9 2
2 10 2
154 220 2
147 294 2
998 24435 3
1 1000000000 2
2
6
0
4
0
1
7148
500000000

在线编程 IDE

建议全屏模式获得最佳体验