Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
正整数 N,M が与えられます。
次の条件をともにみたす最小の正整数 X を求めてください。
ただし、そのようなものが存在しない場合は -1 を出力してください。
- 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 以下の整数 2 つの積として表すことはできません。
次に、8 は 8=2\times 4 などとして、1 以上 5 以下の整数 2 つの積として表すことができます。
よって、8 を出力します。
入力例 2
2 5
出力例 2
-1
1\times 1=1、1\times 2=2、2\times 1=2、2\times 2=4 より、
1 以上 2 以下の整数 2 つの積として表す事ができるのは 1,2,4 のみであるため、
5 以上の数はそのような整数 2 つの積として表すことができません。
よって、-1 を出力します。
入力例 3
100000 10000000000
出力例 3
10000000000
a=b=100000 (=10^5)とした時、a,b の積は 10000000000 (=10^{10}) となり、これが答えとなります。
答えが 32 bit 整数型に収まらない場合があることに注意してください。
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.