#K69487. Minimum Difference Partitioning

    ID: 33097 Type: Default 1000ms 256MiB

Minimum Difference Partitioning

Minimum Difference Partitioning

You are given several test cases. In each test case, you have n items that need to be divided into k groups. The items must be distributed as evenly as possible. Formally, if we let \(q = \lfloor \frac{n}{k} \rfloor\) and \(r = n \bmod k\), then exactly \(r\) groups will have \(q+1\) items and the remaining \(k - r\) groups will have \(q\) items. The minimum absolute difference between the sizes of any two groups will be 0 if \(r = 0\), or 1 otherwise (if \(k < n\)). In the special case when \(k \ge n\), each item can be placed in a separate group yielding a difference of 0.

Your task is to compute this minimum difference for each test case.

inputFormat

Standard input provides the input in the following format:

T
n1 k1
n2 k2
... 
nT kT

Where T is the number of test cases. For each test case, two space-separated integers n (the number of items) and k (the number of groups) are provided.

outputFormat

For each test case, output a single integer on a new line representing the minimum absolute difference between the sizes of the groups after the items are evenly distributed.

## sample
5
10 3
15 4
7 7
8 4
1 1
1

1 0 0 0

</p>