102963: [Atcoder]ABC296 D - M<=ab
Description
Score : $400$ points
Problem Statement
You are given positive integers $N$ and $M$.
Find the smallest positive integer $X$ that satisfies both of the conditions below, or print $-1$ if there is no such integer.
- $X$ can be represented as the product of two integers $a$ and $b$ between $1$ and $N$, inclusive. Here, $a$ and $b$ may be the same.
- $X$ is at least $M$.
Constraints
- $1\leq N\leq 10^{12}$
- $1\leq M\leq 10^{12}$
- $N$ and $M$ are integers.
Input
The input is given from Standard Input in the following format:
$N$ $M$
Output
Print the smallest positive integer $X$ that satisfies both of the conditions, or $-1$ if there is no such integer.
Sample Input 1
5 7
Sample Output 1
8
First, $7$ cannot be represented as the product of two integers between $1$ and $5$.
Second, $8$ can be represented as the product of two integers between $1$ and $5$, such as $8=2\times 4$.
Thus, you should print $8$.
Sample Input 2
2 5
Sample Output 2
-1
Since $1\times 1=1$, $1\times 2=2$, $2\times 1=2$, and $2\times 2=4$, only $1$, $2$, and $4$ can be represented as the product of two integers between $1$ and $2$,
so no number greater than or equal to $5$ can be represented as the product of two such integers.
Thus, you should print $-1$.
Sample Input 3
100000 10000000000
Sample Output 3
10000000000
For $a=b=100000$ $(=10^5)$, the product of $a$ and $b$ is $10000000000$ $(=10^{10})$, which is the answer.
Note that the answer may not fit into a $32$-bit integer type.
Input
题意翻译
给定正整数 $N$, $M$ 。 求满足以下条件的最小正整数 $X$ 。如果不存在这样的 $X$ 输出 $-1$。 - $X$ 可以表示为两个正整数 $a,b$ $(a,b\in[1,N])$ 的积。注意 $a$ 可以等于 $b$ 。 - $X \ge M$。Output
问题描述
给你两个正整数$N$和$M$。
- $X$可以表示为两个在$1$到$N$(含)之间的整数$a$和$b$的乘积。这里,$a$和$b$可以相同。
- $X$至少为$M$。
约束
- $1\leq N\leq 10^{12}$
- $1\leq M\leq 10^{12}$
- $N$和$M$是整数。
输入
输入将从标准输入按以下格式给出:
$N$ $M$
输出
输出满足两个条件的最小正整数$X$,如果没有这样的整数,则输出$-1$。
样例输入1
5 7
样例输出1
8
首先,$7$不能表示为两个在$1$到$5$之间的整数的乘积。
其次,$8$可以表示为两个在$1$到$5$之间的整数的乘积,如$8=2\times 4$。
因此,你应该输出$8$。
样例输入2
2 5
样例输出2
-1
由于$1\times 1=1$,$1\times 2=2$,$2\times 1=2$,$2\times 2=4$,只有$1$,$2$和$4$可以表示为两个在$1$到$2$之间的整数的乘积,所以没有大于等于$5$的数可以表示为两个这样的整数的乘积。
因此,你应该输出$-1$。
样例输入3
100000 10000000000
样例输出3
10000000000
对于$a=b=100000$ $(=10^5)$,$a$和$b$的乘积为$10000000000$ $(=10^{10})$,这就是答案。
注意答案可能不适用32位整数类型。