CF1839A.The Good Array

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

The Good Array

You are given two integers nn and kk.

An array a1,a2,,ana_1, a_2, \ldots, a_n of length nn, consisting of zeroes and ones is good if for all integers ii from 11 to nn both of the following conditions are satisfied:

  • at least ik\lceil \frac{i}{k} \rceil of the first ii elements of aa are equal to 11,
  • at least ik\lceil \frac{i}{k} \rceil of the last ii elements of aa are equal to 11.

Here, ik\lceil \frac{i}{k} \rceil denotes the result of division of ii by kk, rounded up. For example, 63=2\lceil \frac{6}{3} \rceil = 2, 115=2.2=3\lceil \frac{11}{5} \rceil = \lceil 2.2 \rceil = 3 and 74=1.75=2\lceil \frac{7}{4} \rceil = \lceil 1.75 \rceil = 2.

Find the minimum possible number of ones in a good array.

Input

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

The only line of each test case contains two integers nn, kk (2n1002 \le n \le 100, 1kn1 \le k \le n) — the length of array and parameter kk from the statement.

Output

For each test case output one integer — the minimum possible number of ones in a good array.

It can be shown that under the given constraints at least one good array always exists.

Note

In the first test case, n=3n = 3 and k=2k = 2:

  • Array [1,0,1][ \, 1, 0, 1 \, ] is good and the number of ones in it is 22.
  • Arrays [0,0,0][ \, 0, 0, 0 \, ], [0,1,0][ \, 0, 1, 0 \, ] and [0,0,1][ \, 0, 0, 1 \, ] are not good since for i=1i=1 the first condition from the statement is not satisfied.
  • Array [1,0,0][ \, 1, 0, 0 \, ] is not good since for i=1i=1 the second condition from the statement is not satisfied.
  • All other arrays of length 33 contain at least 22 ones.

Thus, the answer is 22.

In the second test case, n=5n = 5 and k=2k = 2:

  • Array [1,1,0,0,1][ \, 1, 1, 0, 0, 1 \, ] is not good since for i=3i=3 the second condition is not satisfied.
  • Array [1,0,1,0,1][ \, 1, 0, 1, 0, 1 \, ] is good and the number of ones in it is 33.
  • It can be shown that there is no good array with less than 33 ones, so the answer is 33.

In the third test case, n=9n = 9 and k=3k = 3:

  • Array [1,0,1,0,0,0,1,0,1][ \, 1, 0, 1, 0, 0, 0, 1, 0, 1 \, ] is good and the number of ones in it is 44.
  • It can be shown that there is no good array with less than 44 ones, so the answer is 44.

In the fourth test case, n=7n = 7 and k=1k = 1. The only good array is [1,1,1,1,1,1,1][ \, 1, 1, 1, 1, 1, 1, 1\, ], so the answer is 77.

Samples

7
3 2
5 2
9 3
7 1
10 4
9 5
8 8
2
3
4
7
4
3
2

在线编程 IDE

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