#P11184. Possible Remainders in Division with Remainder

    ID: 13250 Type: Default 1000ms 256MiB

Possible Remainders in Division with Remainder

Possible Remainders in Division with Remainder

Given two integers, the dividend \(n\) and the quotient \(k\) from a division with remainder, where the division is represented as

\( n = k \times q + r \)

with the condition \(0 \le r < q\) (even when \(r=0\), the remainder is explicitly written), determine the number of distinct possible values of the remainder \(r\) when the divisor \(q\) is unknown.

More formally, for a valid division with remainder of two positive integers, if \(q\) and \(r\) satisfy

\[ \begin{aligned} n &= k\,q + r,\\ 0 &\le r \frac{n}{k+1} \quad \text{(since }n - kq < q\text{)} \end{aligned} \]

and if \(k=0\) then \(n=r\) with any \(q > n\) (yielding a unique remainder), your task is to count the number of distinct remainders that can appear.

Hint: For \(k>0\), the possible divisors \(q\) are those integers satisfying

\[ \frac{n}{k+1} < q \le \frac{n}{k}, \]

so the number of possibilities is:

\( \lfloor \frac{n}{k} \rfloor - \lfloor \frac{n}{k+1} \rfloor \).

For the case \(k=0\), there is exactly one possible remainder.

inputFormat

The input consists of a single line containing two integers \(n\) and \(k\) separated by spaces, where \(n\) is the dividend and \(k\) is the quotient.

outputFormat

Output a single integer representing the number of distinct possible remainders \(r\).

sample

10 2
2