C - Remainder Minimization 2019 Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

非負整数 L,RL, R が与えられます。 22 つの整数 i,ji, jLi<jRL \leq i < j \leq R を満たすように選びます。 (i×j) mod 2019(i \times j) \text{ mod } 2019 の最小値を求めてください。

制約

  • 入力は全て整数
  • 0L<R2×1090 \leq L < R \leq 2 \times 10^9

入力

入力は以下の形式で標準入力から与えられる。

LL RR

出力

条件を満たすように i,ji, j を選んだ時の、(i×j) mod 2019(i \times j) \text{ mod } 2019 の最小値を出力せよ。


入力例 1Copy

Copy
2020 2040

出力例 1Copy

Copy
2

(i,j)=(2020,2021)(i, j) = (2020, 2021) とすると、(i×j) mod 2019=2(i \times j) \text{ mod } 2019 = 2 となります。


入力例 2Copy

Copy
4 5

出力例 2Copy

Copy
20

選び方は (i,j)=(4,5)(i, j) = (4, 5)11 通りしか存在しません。

Score : 300300 points

Problem Statement

You are given two non-negative integers LL and RR. We will choose two integers ii and jj such that Li<jRL \leq i < j \leq R. Find the minimum possible value of (i×j) mod 2019(i \times j) \text{ mod } 2019.

Constraints

  • All values in input are integers.
  • 0L<R2×1090 \leq L < R \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

LL RR

Output

Print the minimum possible value of (i×j) mod 2019(i \times j) \text{ mod } 2019 when ii and jj are chosen under the given condition.


Sample Input 1Copy

Copy
2020 2040

Sample Output 1Copy

Copy
2

When (i,j)=(2020,2021)(i, j) = (2020, 2021), (i×j) mod 2019=2(i \times j) \text{ mod } 2019 = 2.


Sample Input 2Copy

Copy
4 5

Sample Output 2Copy

Copy
20

We have only one choice: (i,j)=(4,5)(i, j) = (4, 5).



2025-03-31 (Mon)
10:36:20 +00:00