問題文
整数 () が与えられます.
すぬけ君は,以下の条件を両方満たす整数の組 を探しています.
条件を満たす組において, がとりうる最大の値を求めてください. なお,問題の制約より,条件を満たす組が少なくとも一つ存在することが証明できます.
制約
入力
入力は以下の形式で標準入力から与えられる.
出力
答えを出力せよ.
入力例 1 Copy
Copy
2 4
出力例 1 Copy
Copy
1
とすると, となってしまい,条件を満たしません. とすれば条件を満たし,このとき の値は です. の値がこれより大きくなることはないため,答えは です.
入力例 2 Copy
Copy
14 21
出力例 2 Copy
Copy
5
入力例 3 Copy
Copy
1 100
出力例 3 Copy
Copy
99
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void solve() { | |
// input | |
ll r, l; | |
cin >> l >> r; | |
ll ans = 1LL; | |
// prime number must be found in 1500 | |
int d = 1500; | |
for (int i = 0; i <= d; i++) { | |
for (int j = 0; j <= d; j++) { | |
if (gcd(l + i, r - j) < 2) chmax(ans, r - j - (l + i)); | |
} | |
} | |
out(ans); | |
} |
No comments:
Post a Comment