We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

- Practice
- Mathematics
- Geometry
- Sherlock and Counting

# Sherlock and Counting

# Sherlock and Counting

Watson gives Sherlock two integers, and , and asks him to count the number of positive integer 's such that:

Given queries where each query consists of some and , print the number of possible 's for each query on a new line.

**Input Format**

The first line contains an integer, , denoting the number of times Watson queries Sherlock.

Each of the subsequent lines contains two space-separated integers denoting the respective values of and for a query.

**Constraints**

**Output Format**

For each query, print the number of 's satisfying the given formula on a new line.

**Sample Input**

```
2
5 1
5 2
```

**Sample Output**

```
2
4
```

**Explanation**

Sherlock performs the following queries:

- The possible values of satisfying Watson's formula for and are and . Because there are two such values, we print on a new line.
- The possible values of satisfying Watson's formula for and are , , , and . Because there are four such values, we print on a new line.