P6511 [QkOI#R1] Quark and Equations

Description

Given $n, m$, find how many pairs of positive integers $(i, j)$ satisfy the following system of equations: $$ \begin{cases} i+j=n \\ \lfloor\frac{i}{j}\rfloor+\lceil\frac{j}{i}\rceil=m \end{cases} $$ In the above, $\lfloor x\rfloor$ denotes rounding $x$ down, and $\lceil x\rceil$ denotes rounding $x$ up.

Input Format

**This problem contains multiple test cases in a single input file.** The first line contains an integer $T$, indicating the number of test cases. The next $T$ lines each contain two integers $n, m$, with the meaning as described in the statement.

Output Format

Your output should contain $T$ lines. For each test case, output one integer per line representing your answer.

Explanation/Hint

### Sample Explanation When $n=m=2$, only $(1,1)$ satisfies the conditions. When $n=2,m=1$, there is no solution. When $n=6,m=2$, only $(2,4)$ and $(3,3)$ satisfy the conditions. --- ### Constraints **This problem uses bundled testdata.** - Subtask 1 (10 pts): $T, n, m\le 500$. - Subtask 2 (40 pts): $T, n, m\le 5000$. - Subtask 3 (5 pts): $m=1$. - Subtask 4 (5 pts): $m>n$. - Subtask 5 (5 pts): $m\in[n-1,n]$. - Subtask 6 (35 pts): no special constraints. For $100\%$ of the testdata, $1\le T\le 10^5$, $1\le n,m\le 10^{7}$. Translated by ChatGPT 5