Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
整数 L,R (L < R) が与えられます.
すぬけ君は,以下の条件を両方満たす整数の組 (x,y) を探しています.
- L \leq x < y \leq R
- \gcd(x,y)=1
条件を満たす組において,(y-x) がとりうる最大の値を求めてください. なお,問題の制約より,条件を満たす組が少なくとも一つ存在することが証明できます.
制約
- 1 \leq L < R \leq 10^{18}
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる.
L R
出力
答えを出力せよ.
入力例 1
2 4
出力例 1
1
(x,y)=(2,4) とすると,\gcd(x,y)=2 となってしまい,条件を満たしません. (x,y)=(2,3) とすれば条件を満たし,このとき (y-x) の値は 1 です. (y-x) の値がこれより大きくなることはないため,答えは 1 です.
入力例 2
14 21
出力例 2
5
入力例 3
1 100
出力例 3
99
Score : 300 points
Problem Statement
You are given integers L,R (L < R).
Snuke is looking for a pair of integers (x,y) that satisfy both of the conditions below.
- L \leq x < y \leq R
- \gcd(x,y)=1
Find the maximum possible value of (y-x) in a pair that satisfies the conditions. It can be proved that at least one such pair exists under the Constraints.
Constraints
- 1 \leq L < R \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
L R
Output
Print the answer.
Sample Input 1
2 4
Sample Output 1
1
For (x,y)=(2,4), we have \gcd(x,y)=2, which violates the condition. For (x,y)=(2,3), the conditions are satisfied. Here, the value of (y-x) is 1. There is no such pair with a greater value of (y-x), so the answer is 1.
Sample Input 2
14 21
Sample Output 2
5
Sample Input 3
1 100
Sample Output 3
99