#P10782. Finding a Valid b
Finding a Valid b
Finding a Valid b
Given five positive integers \(n, m, a, b, c\) satisfying
\(b = \left\lfloor \frac{a}{n} \right\rfloor\) and \(c = \left\lfloor \frac{b}{m} \right\rfloor\), where the floor function \(\lfloor X \rfloor\) is defined as the greatest integer less than or equal to \(X\) (e.g. \(\lfloor 1.99 \rfloor = 1\), \(\lfloor 7 \rfloor = 7\)).
You are given the values of \(a\) and \(c\). Your task is to output a positive integer \(b\) for which there exist positive integers \(n\) and \(m\) satisfying the above equations. If multiple valid values of \(b\) exist, output any one of them. If no such value exists, output -1
.
Notes:
- The condition \(b = \left\lfloor \frac{a}{n} \right\rfloor\) implies that there exists a positive integer \(n\) satisfying \[ \frac{a}{b+1} < n \le \frac{a}{b}, \] and similarly, \(c = \left\lfloor \frac{b}{m} \right\rfloor\) implies that there exists a positive integer \(m\) satisfying \[ \frac{b}{c+1} < m \le \frac{b}{c}. \]
inputFormat
The input consists of a single line containing two positive integers \(a\) and \(c\) separated by a space.
outputFormat
Output a valid positive integer \(b\) that satisfies the conditions. If no valid \(b\) exists, output -1
.
sample
10 3
3