P16463 [CodeChef] MODEQ
提高-
题目描述

Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.

------ Input ------

The first line contains an integer $T$, the number of test cases. Then the test cases follow.
The only line of each test case contains two integers $N$, $M$.

------ Output ------
For each testcase, output in a single line the answer to the problem.

------ Constraints ------
$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 10^{6}$
$1 ≤ M ≤ 5\cdot 10^{5}$
The sum of $N$ over all test cases does not exceed $10^{6}$.

Note: Multiplier for JAVA for this problem is reduced to $1.25$ instead of usual $2$.

------ Subtasks ------
Subtask #1 (10 points):
$1 ≤ T ≤ 10$
$2 ≤ N ≤ 10^{3}$
$1 ≤ M ≤ 10^{5}$

Subtask #2 (40 points):
$1 ≤ T ≤ 100$
$2 ≤ N ≤ 10^{5}$
$1 ≤ M ≤ 10^{5}$
The sum of $N$ over all test cases does not exceed $10^{6}$.

Subtask #3 (50 points): Original Constraints

----- Sample Input 1 ------
3

3 5

3 6

3 10
----- Sample Output 1 ------
2

3

2
----- explanation 1 ------
Test Case $1$: There are $2$ valid pairs satisfying the conditions. These are:
- $(1, 2)$: $(1 ≤ 1 < 2 ≤ N)$. Given $M = 5$, $((5 \%1) \%2) = (0\%2) = 0$. Also, $((5 \%2) \%1) = (1\%1) = 0$.
- $(1, 3)$: $(1 ≤ 1 < 3 ≤ N)$. Given $M = 5$, $((5 \%1) \%3) = (0\%3) = 0$. Also, $((5 \%3) \%1) = (2\%1) = 0$.

Test Case $2$: There are $3$ valid pairs satisfying the conditions. These are:
- $(1, 2)$: $(1 ≤ 1 < 2 ≤ N)$. Given $M = 6$, $((6 \%1) \%2) = (0\%2) = 0$. Also, $((6 \%2) \%1) = (0\%1) = 0$.
- $(1, 3)$: $(1 ≤ 1 < 3 ≤ N)$. Given $M = 6$, $((6 \%1) \%3) = (0\%3) = 0$. Also, $((6 \%3) \%1) = (0\%1) = 0$.
- $(2, 3)$: $(1 ≤ 2 < 3 ≤ N)$. Given $M = 6$, $((6 \%2) \%3) = (0\%3) = 0$. Also, $((6 \%3) \%2) = (0\%2) = 0$.

Test Case $3$: There are $2$ valid pairs satisfying the conditions. These are:
- $(1, 2)$: $(1 ≤ 1 < 2 ≤ N)$. Given $M = 10$, $((10 \%1) \%2) = (0\%2) = 0$. Also, $((10 \%2) \%1) = (0\%1) = 0$.
- $(1, 3)$: $(1 ≤ 1 < 3 ≤ N)$. Given $M = 10$, $((10 \%1) \%3) = (0\%3) = 0$. Also, $((10 \%3) \%1) = (1\%1) = 0$.

输入格式

见题面

输出格式

见题面

样例输入
3 3 5 3 6 3 10
样例输出
2 3 2