#P6511. Counting Integer Pairs with Floor and Ceiling Conditions

    ID: 19724 Type: Default 1000ms 256MiB

Counting Integer Pairs with Floor and Ceiling Conditions

Counting Integer Pairs with Floor and Ceiling Conditions

Given two positive integers n and m, count the number of pairs of positive integers (i, j) that satisfy the following system of equations:

$$\begin{cases} i+j=n \\ \lfloor\frac{i}{j}\rfloor+\lceil\frac{j}{i}\rceil=m \end{cases} $$

Here, \(\lfloor x\rfloor\) denotes the floor of \(x\) (i.e. the greatest integer less than or equal to \(x\)), and \(\lceil x\rceil\) denotes the ceiling of \(x\) (i.e. the smallest integer greater than or equal to \(x\)).

You are required to count how many pairs \((i,j)\) (with both \(i>0\) and \(j>0\)) satisfy the above equations.

inputFormat

The input consists of two space-separated positive integers n and m.

Constraints: You may assume that n and m are such that the solution can be computed using a simple iterative approach.

outputFormat

Output a single integer: the number of pairs (i, j) that satisfy the given conditions.

sample

5 3
0