Problem:


Score : 300 points

Problem Statement

You are given two non-negative integers L and R.
We will choose two integers i and j such that L \leq i < j \leq R.
Find the minimum possible value of (i \times j) \mbox{ mod } 2019.

Constraints

All values in input are integers.

0 \leq L < R \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

L R

Output

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

Sample Input 1

2020 2040

Sample Output 1

2

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

Sample Input 2

4 5

Sample Output 2

20

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



Sample input:
2020 2040


Sample output:
2

Submission status: Accepted

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # open(0).read() is a convenient method:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')

    # ----------------------------------
    # main
    
    # 2019 => 1, 3, 673, 2019
    inputL, inputR = R()
    md = 2019
    modl = inputL % md
    modr = inputR % md
    
    if inputR - inputL >= 2018 or modl > modr:
        print(0)
        exit()
    
    ans = 10000000000000000
    for i in range(modl, modr+1):
        for j in range(modl, modr+1):
            if i == j:
                continue
            else:
                ans = min(ans, (i*j)%md)
    
    print(ans)
    # print(min(modl*(modl+1), modr*(modr+1)))
    # if inputL > inputR:
    #     print(inputL * (inputL+1))
    # else:
    #     print(inputR * (inputR+1))
        
        
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # for
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    result = 2019
    L, R = [int(x) for x in stdin.readline().rstrip().split()]
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            a = (i * j) % 2019
            result = min(result, a)
            if (result == 0):
                print(result)
                return
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

L, R = map(int, input().split())

res = 2020
if R-L >= 2019:
    print(0)
else:
    for i in range(L, R):
        if res==0: break
        for j in range(i+1, R+1):
            if res==0: break
            
            new_res = (i*j)%2019
            if new_res < res:
                res = new_res
    print(res)

Submission status: Accepted

Solution code:
l, r = map(int, input().split())
mod = 2019
if l//mod < r//mod:
  print(0)
  exit()
l %= mod
r %= mod
m = mod-1
for i in range(l, r+1):
  for j in range(i+1, r+1):
    m = min(m, (i * j) % mod)
print(m)

Submission status: Accepted

Solution code:
L,R = map(int,input().split())

left = L % 2019
c = 2019 - left
if L + c <= R:
    ans = 0
else:
    ans = 2020
    right = R % 2019
    for i in range(left,right+1):
        for j in range(i+1,right+1):
            ans = min((i*j)%2019,ans)
print(ans)

Submission status: Accepted

Solution code:
L,R=map(int,input().split())
l1=L//2019
l2=L%2019
r1=R//2019
r2=R%2019
if l1!=r1 or l2==0:
  print(0)
else:
  a = [2020]
  for i in range(l2,r2):
    for j in range(i+1,r2+1):
      c = (i*j)%2019
      a.append(c)
  print(min(a))

Submission status: Accepted

Solution code:
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    rem_value = 2019
    [l, r] = li()
    l_mod = l % rem_value
    r_mod = r % rem_value
    if r - l >= 2019 or l_mod > r_mod:
        print(0)
    else:
        candidate = range(l_mod, r_mod + 1)
        min_value = rem_value
        for index, i in enumerate(candidate[:-1]):
            for j in candidate[index + 1:]:
                if i * j % rem_value < min_value:
                    min_value = i * j % rem_value
        print(min_value)

# 2019の倍数があれば0　L以上の2019の倍数で最小のものがR以下　Lが0の場合も0
# 2019 = 3 * 673

# 言い換え
# 3の倍数と673の倍数が両方あれば0　L以上の3の倍数で最小のものがR以下　かつ　L以上の673の倍数で最小のものがR以下　Lが0の場合も0
# i * j mod 2019 = (i mod 2019 * j mod 2019) mod 2019
# 0-2018で使える使えないが決まる
# 全ての組み合わせ　最悪　2019 C 2
# 全ての組み合わせを調べる

Submission status: Accepted

Solution code:
L, R = map(int, input().split())
mod = []
for i in range(L, R+1):
    if i % 2019 not in mod:
        mod.append(i % 2019)
    else:
        break

ans = mod[0] * mod[1] % 2019
for i in range(len(mod)):
    for j in range(i+1, len(mod)):
        if mod[i] * mod[j] % 2019 <= ans:
            ans = mod[i] * mod[j] % 2019
print(ans)

Submission status: Accepted

Solution code:
left, right = map(int, input().split())

min = 2019
for i in range(left, right+1):
    for j in range(i+1, right+1):
        tmp = (i * j) % 2019
        if tmp < min:
            min = tmp
        if min == 0:
            print(min)
            exit()

print(min)

Submission status: Accepted

Solution code:
import itertools
L, R = map(int, input().split())
if R - L > 2019:
    R = L + 2019
li = set([i%2019 for i in range(L, R+1)])

min = 2019
for i in itertools.combinations(li,2):
    tmp = i[0]*i[1]%2019
    if min > tmp:
        min = tmp
print(min)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
mine = 2019
if b - a > 2017:
    print(0)
else:
    a = a%2019
    b = b%2019
    if a>b :
        print(0)
    else:
        for i in range(b-a):
            for f in range(b-a-i):
                mine = min(mine, ((a+i)*(a+i+1+f))%2019)
        print(mine)

Submission status: Accepted

Solution code:
l, r = map(int,input().split())

lmod=l%2019
rmod=r%2019

if r-l>=2019:
    mini = 0
elif l <= 2019*(r//2019):
    mini = 0
else:
    mini = 10**9
    for i in range(lmod,rmod+1):
        for j in range(i+1,rmod+1):
            mini = min(mini,(i*j)%2019)
print(mini)

Submission status: Accepted

Solution code:
L,R=map(int,input().split())

if L==0:
    print(0)
elif L%2019==0 or R%2019==0:
    print(0)
elif (R-L)>=2019:
    print(0)
elif (L//2019)<(R//2019):
    print(0)
else:
    A=[]
    for i in range(L,R+1):
        A.append(i%2019)
    M=10000
    for i in range(len(A)-1):
        for j in range(i+1,len(A)):
            if (A[i]*A[j])%2019<M:
                M=(A[i]*A[j])%2019
    print(M)

Submission status: Accepted

Solution code:
l, r = map(int, input().split())

if l//2019 != r//2019:
    print(0)
else:
    ans = 2019
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, (i*j)%2019)
    print(ans)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())

if R - L >= 2019 - 1:
    print(0)
    exit()

ans = 2020
for i in range(L, R):
    for j in range(i+1, R+1):
        ans = min(ans, (i*j) % 2019)
        
print(ans)

Submission status: Accepted

Solution code:
l, r = map(int, input().split())

if r - l + 1 >= 2019:
    print(0)
    exit()

e = min(r + 1, l + 2019)
ans = 2019
for i in range(l, e):
    for j in range(i + 1, e):
        ans = min(ans, (i * j) % 2019)

print(ans)

Submission status: Accepted

Solution code:
l,r=map(int,input().split())
L=l%2019
R=r%2019
ans=2019
if l+2019<=r:
        print(0)
elif L>R:
        print(0)
else:
        for i in range(L,R+1):
              for j in range(i+1,R+1):
                        ans=min(ans,(i*j)%2019)
        print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

L, R = map(int, input().split())

min = 2019

if R - L > 2019:
    R = L + 2019

for i in range(L, R+1):
    for j in range(i+1, R+1):
        mod = (i*j) % 2019
        if mod < min:
            min = mod

print(min)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 20

# 0<= L < R <= 2*10^9 
L, R = [int(x) for x in stdin.readline().rstrip().split()]
MODN = 2019

#if R < 2019:
#    print(L*R)
#    exit()

ans = INF
for i in range(L, L + 2019 + 3):
    if i > R:
        break
    for j in range(i+1, L + 2019 + 3):
        if j > R:
            break

        tmp = (i * j) % MODN
        ans = min(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline

l, r = map(int, fin().split())

if (r - l) > 700:
    print(0)

else:
    num = list(range(l, r + 1))
    num = [n % 2019 for n in num]
    mul = [(num[i] * num[j]) % 2019 for i in range(len(num) - 1) for j in range(i + 1, len(num))]
    print(min(mul))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations
def solve():
    L, R = map(int, input().split())
    l, r = L%2019, R%2019
    if R-L >= 2019-1 or l >= r or l == 0:
        return '0'
    elif R-L >= 673-1 or ((R-L >= 3-1 or L%3 >= R%3 or L%3 == 0) and L%673 >= R%673) or ((R-L >= 3-1 or L%3 >= R%3 or L%3 == 0) and L%673 == 0):
        return '0'
    elif R-L == 1:
        return str((L*R)%2019)
    else:
        return str(min((i*j)%2019 for i, j in combinations(range(L,R+1),r=2)))

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
l, r = map(int, input().split())
if r - l >= 2018:
  print(0)
  exit()
l = l % 2019
r = r % 2019
if l > r:
  r += 2019
ans = 2019
for i in range(l, r):
  for j in range(i+1, r+1):
    ans = min(ans,i*j%2019)
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    L,R = map(int, input().split())

    ans = sys.maxsize

    # 0 がある場合
    # 0 がない場合→全探索

    if R//2019 - (L-1)//2019 > 0:
        return 0
    
    if R//673 - (L-1)//673 > 0 and R//3 - (L-1)//673 > 0:
        return 0

    for i in range(L,R+1):
        for j in range(i+1,R+1):
            ans = min(ans, i*j%2019)
    
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import sys

l, r = list(map(int, input().split()))

ans = 2018

for i in range(l, r + 1):
  for j in range(i + 1, r + 1):
    if ((i * j) % 2019) < ans:
      ans = (i * j) % 2019
    if ans == 0:
      print(ans)
      sys.exit()

print(ans)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())

# L ≤ i < j ≤ R

#(i×j)mod2019


l_mod = L % 2019
r_mod = R % 2019

l_count = L // 2019
r_count = R // 2019

min_mod2019 = 2020

if l_count < r_count: # 2019 の倍数を跨いでいるとき
    print(0)
    
elif l_count == r_count: # 2019 の倍数を跨がないとき
    for i in range(l_mod, r_mod):
        for j in range(i+1, r_mod+1):
            tmp = (i * j) % 2019
            if tmp < min_mod2019:
                min_mod2019 = tmp
    print(min_mod2019)

Submission status: Accepted

Solution code:
# coding; utf-8
l, r = map(int, input().split())

if r-l > 2019:
        ans = 0
else:
        ans = 2019
        l = l%2019
        r = r%2019
        if l > r:
                r += 2019
        for i in range(l, r):
                for j in range(l+1, r+1):
                        if (i*j) % 2019 < ans:
                                ans = (i*j) % 2019

print(ans)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())
x = [i % 2019 for i in range(L, min(R + 1, L + 2019))]
ans = 10 ** 10
for i in x:
    for j in x:
        if i < j:
            ans = min(ans, i * j % 2019)
print(ans)

Submission status: Accepted

Solution code:
l, r = map(int, input().split())

if r - l > 2020:
    r = l + 2020

ans = 2020
for i in range(l,r):
    for j in range(i+1,r+1):
        sub = (i*j)%2019

        if sub < ans:
            ans = sub

print(ans)

Submission status: Accepted

Solution code:
L,R = map(int,input().split())
if R-L>=2019:print(0)
else:
    L%=2019
    R%=2019
    if R<L:R+=2019
    ans = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans = min(ans,i*j%2019)
    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

l,r=intinput()
mod=2019
if r-l>=mod:
    print(0)
    sys.exit()
s=l%mod
t=r%mod
if s>t: print(0)
else:
    ans=float("inf")
    for i in range(s,t+1):
        for j in range(i+1,t+1):
            ans=min(ans,i*j%mod)
    print(ans)

Submission status: Accepted

Solution code:
l, r = map(int, input().split())

li=[]
cnt=0
for i in range(l, r+1):
  li.append(i%2019)
  if i%2019==0:
    print(0)
    break
else:
  ans=2019
  for index, i in enumerate(li):
    for j in li[index+1:]:
      ans = min(ans, (i*j)%2019)
  print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    L, R = map(int, input().split())
    if R - L >= 2019:
        print(0)
    elif R % 2019 == 0 or L % 2019 == 0:
        #どっちかが、2019の倍数の時
        print(0)
    elif R % 2019 <= L % 2019:
        # 200 2020みたいな
        print(0)
    else:
        min_value = 2020
        for i in range(L, R + 1):
            for j in range(i + 1, R + 1):
                mod_value = (i * j) % 2019
                min_value = min(mod_value, min_value)
        print(min_value)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
L,R=map(int,input().split())
if R - L > 2019:
      print(0)
else:
    D = R - L
    L = L % 2019
    R = L + D
    a = 2018
    for i in range(D):
        for j in range(i+1,D+1):
            if (L+i)*(L+j)%2019 < a:
                a =(L+i)*(L+j)%2019
    print(a)

Submission status: Accepted

Solution code:

L, R = [int(x) for x in input().split(' ')]

if L <= 2019 and 2019 <= R:
    print(0)
    exit(0)
if 2018 <= (R - L):
    print(0)
    exit(0)

min_val = 2020
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        val = (i * j) % 2019
        min_val = min(min_val, val)
print(min_val)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())

border = (R//2019 - L//2019)

if border >= 1 or ((R%2019)==0) or ((L%2019)==0):
  print(0)
else:
  L %= 2019
  R %= 2019
  ans = 2019
  for i in range(L, R):
    for j in range(i+1, R+1):
      ans = min(ans, (i*j)%2019)
  print(ans)

Submission status: Accepted

Solution code:
import itertools
L,R=map(int,input().split())
if R-L>=2019:
  print(0)
else:
  MIN=2018  
  list1=list(range(L,R+1))
  list2=list(itertools.combinations(list1,2))
  for i in range(len(list2)):
    a=list2[i][0]*list2[i][1]%2019
    MIN=min(MIN,a)
  print(MIN)

Submission status: Accepted

Solution code:
l,r=map(int,input().split())
a=[]
if r//2019!=l//2019 or r%2019==0 or l%2019==0:
	print(0)
else:
	rr=r%2019
	ll=l%2019
	for i in range(ll,rr+1):
		for k in range(ll,rr+1):
			if i<k:
				a.append(i*k%2019)
	print(min(a))

Submission status: Accepted

Solution code:
L, R  = map(int, input().split())

X = [x % 2019 for x in range(L, min(L+2019+1, R+1))]

ans = 2019
for i, x_i in enumerate(X):
    for j, x_j in enumerate(X[i+1:]):
        ans = min(ans, x_i*x_j % 2019)
print(ans)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())
mod = 2019

if R - L >= 2019:
    print(0)
else:
    ans = float('inf')
    for i in range(L, R+1):
        for j in range(i+1, R+1):
            ans = min((i * j) % mod, ans)
    print(ans)

Submission status: Accepted

Solution code:
import sys
l,r = map(int, input().split())

if r == l+1:
    print((l*r)%2019)
    sys.exit()

for i in range(1,10**6+1):
    v = 2019*i
    if l<=v and r>=v:
        print(0)
        sys.exit()

ans = 2020
for i in range(l,r):
    for j in range(i+1,r+1):
        dp = (i*j)%2019
        if ans>dp:
            ans = dp

print(ans)

Submission status: Accepted

Solution code:
def check(l,r):
    if r-l>=2019:
        return True
    if r%2019<l%2019:
        return True
    else:
        return False
l,r=map(int,input().split())
if check(l,r):
    print(0)
else:
    l%=2019
    r%=2019
    ans=2019
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans=min((i*j)%2019,ans)
    print(ans)

Submission status: Accepted

Solution code:
import sys
l,r = map(int,input().split())
if r - l >= 2018:
  print(0)
  sys.exit()
l = l % 2019
r = r % 2019
if r <= l:
  print(0)
  sys.exit()
m = 2019
for i in range(l,r):
  for j in range(i+1,r+1):
    m = min(m,i*j%2019)
print(m)

Submission status: Accepted

Solution code:
import itertools as itr

l,r = map(int,input().split())

l_r = l % 2019
r_r = r % 2019
l_q = l // 2019
r_q = r // 2019


if r_q > l_q:
	print(0)
else:

	vals = range(l_r,r_r+1)

	print(min([(a*b)%2019 for a,b in itr.combinations(vals, 2)]))

Submission status: Accepted

Solution code:
L, R = map(int, input().split())
MOD = 2019

if R - L >= MOD - 1:
    print(0)
    exit()

if L % MOD < R % MOD:
    a = [n for n in range(L % MOD, R % MOD + 1)]
elif L % MOD > R % MOD:
    a = [n for n in range(L % MOD, MOD)] + [n for n in range(R % MOD + 1)]
else:
    a = list(range(MOD))

ans = MOD - 1
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        ans = min(ans, (a[i] * a[j]) % MOD)

print(ans)

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    L, R = MAP()
    LL = L % 2019
    RR = R % 2019
    if (R - L) >= 2019:
        print(0)
    else:
        minv = 2019
        for l in range(LL, RR):
            for r in range(l + 1, RR + 1):
                minv = min(minv, (l * r) % 2019)
        print(minv)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
  l,r = (int(i) for i in input().split())
  mod = 2019
  if r-l >= 2019:
   print(0)
   exit()
  l %= mod
  r %= mod
  ans = 10**15
  if l >= r :
    print(0)
    exit()
  elif l == 0 or r == 0:
    print(0)
    exit()
  else:
    for i in range(l,r):
      for j in range(i+1,r+1):
         ans = min(ans,(i*j)%mod)
  print(ans%mod)

solve()

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from itertools import product, combinations
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    l, r = LI()
    mods = [[INF for i in range(2019)] for j in range(2019)]
    ans = INF
    for i, j in product(range(2019), range(2019)):
        mods[i][j] = i * j % 2019
    if r - l >= 2019:
        print(0)
        return
    l = l % 2019
    r = r % 2019
    if r > l:
        for i, j in combinations(range(l, r+1), 2):
            if i == j:
                continue
            ans = min(ans, mods[i][j])
        print(ans)
        return
    print(0)








if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
l, r = list(map(int, input().split()))

if r - l > 2018:
    print(0)
else:
    ans = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            tmp = (i * j) % 2019
            if ans > tmp:
                ans = tmp
    print(ans)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())
diff = R - L

min_temp = 10000
if diff <= 2019:
    for i in range(L, R + 1):
        for j in range(L, R + 1):
            if i == j:
                continue
            x = (i * j) % 2019
            min_temp = min(x, min_temp)
else:
    for i in range(L, L + 1 + 2019):
        for j in range(L, L + 1 + 2019):
            if i == j:
                continue
            x = (i * j) % 2019
            min_temp = min(x, min_temp)
print(min_temp)

Submission status: Accepted

Solution code:
L, R = map(int,input().split())
ans = 2019
if R-L >= 2019:
    ans = 0
else:
    ans = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            mod_ij = (i*j)%2019
            #print(mod_ij)
            if mod_ij < ans:
                ans = mod_ij

print(ans)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())

if R >= L + 2019:
    print('0')
else:
    xs = [x % 2019 for x in range(L, R + 1)]
    vs = []
    for i in range(len(xs)):
        for j in range(i + 1, len(xs)):
            vs.append((xs[i] * xs[j]) % 2019)
    print(min(vs))

Submission status: Accepted

Solution code:
L, R = [int(c) for c in input().split()]

if R-L+1 >= 2019:
    print(0)
    exit()

m = 2020
l = [c%2019 for c in range(L,R+1)]
for i in range(len(l)):
    for j in range(i+1, len(l)):
        m = min(m, (l[i]*l[j])% 2019)
print(m)

Submission status: Accepted

Solution code:
L, R = map(int, input().split())
explore_list = []
def explore(L, R):
    for i in range(L, min(L+2020, R + 1)):
        explore_list.append(i % 2019)

explore(L, R)
answer_list = []
for i in range(len(explore_list)):
    for j in range(i + 1, len(explore_list)):
        answer_list.append(explore_list[i] * explore_list[j] % 2019)

print(min(answer_list))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc133/tasks/abc133_c

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    l, r = map(int, input().split())

    l_i = l // 2019
    r_i = r // 2019
    if l_i != r_i:
        print(0)
    else:
        ans = l * r % 2019
        for x in range(l, r):
            for y in range(l + 1, r + 1):
                ans = min(ans, x * y % 2019)
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
L, R = map(int, input().split())
mod = 2019
if R - L >= mod:
    x = list(range(mod))
else:
    x = list(range(L,R+1))
print(min(i*j % mod for j in x for i in x if j != i))

Submission status: Accepted

Solution code:
L, R = (int(_) for _ in input().split())  

result = 2020

if R - L > 2020:
    result = 0
else:
    for i in range(L, R+1):
        for j in range(L, R+1):
            if i < j:
                result = min(result, (j * i) % 2019)

print(result)