peterverebics/CodeNet_Python_118 huggingface dataset:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    if L - R + 1 >= 2019:
        print(0)
    else:
        L %= 2019
        R %= 2019
        if L > R:
            print(0)
        else:
            print(L * (L + 1))

    return


if __name__ == '__main__':
    main()
L, R = map(int, input().split())

num = 0
ans = (L * (L + 1)) % 2019
if (R - L) > 2020:
    ans = 0
else:
    for i in range(L, R):
        j = i + 1
        ans = min(ans, (i * j) % 2019)
print(ans)
l, r = [int(i) % 2019 for i in input().split()]
print (l * (l + 1))
L, R = map(int, input().split())
if R - L > 2019:
  print(0)
else:
  l = sorted([i % 2019 for i in range(L, R + 1)])
  print(l[0] * l[1])
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    if L - R > 10000:
        print(0)
    else:
        A = [i % 2019 for i in range(L, R + 1)]
        A.sort()
        print((A[0] * A[1]) % 2019)

    return


if __name__ == '__main__':
    main()
l,r=map(int,input().split())
l=l%2019
r=r%2019
ans = float("inf")
for i in range(l,r+1):
    for j in range(l,r+1):
        if i<j:
            ans=min(ans,(i*j)%2019)
print(ans)
L,R = map(int,input().split())

ans = 2019
for i in range(L,R):
    if (i*(i+1))%2019 <= ans :
        ans = (i*(i+1))%2019
        if ans == 0 :
            break

print(ans)
l,r=map(int,input().split())
l_mod=l%2019
r_mod=r%2019
l_div=l//2019
r_div=r//2019
if l_div<r_div:
  print(0)
else:
  print(l_mod*(l_mod+1))
#余り同士の掛け算で２０１９を超えた場合modが小さくなることをかんがえていないためwa
l,r = map(int,input().split())

x = []

if r-l >4038:
    print(0)
else:
    for i in range(l,r+1):
        x.append(i%2019)
    x.sort()
    print(x[0]*x[1]%2019)
l, r = map(int, input().split())
l, r = l%2019, r%2019

ans = 10**10
for i in range(l, r+1):
    for j in range(l, r+1):
        if i < j:
            ans = min(ans, (i*j)%2019)
print(ans)
a,b=map(int,input().split())
c=[]
for i in range(a,b+1):
  for j in range(a,b+1):
    if i<j:
        print(i,j)
        c.append((i*j)%2019)
print(min(set(c)))
L, R = map(int , input().split())

ans = 10 ** 9
for i in range(L, R+1):
    for j in range(i, R):
        mod = i * j % 2019
        if ans > mod:
            ans = mod
        if ans == 0:
            break
    else:
        continue
    break
print(ans)
L, R = map(int, input().split())
rL = L % 2019
rR = R % 2019

if rL < rR and R-L < 2019:
    print((rL * (rL+1))%2019)
else:
    print(0)
l, r = list(map(int, input().split()))


mod = 2019
a = l//mod
b = r//mod

if b-a > 0:
    print(0)
else:
    m = 2020
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            a = (i % mod)*(j % mod)
            if a < m:
                m = a

    print(m)
L, R = map(int, input().split())
MOD = 2019
L %= MOD
R = min(L+1, R % MOD)
print(L*R)
L, R = map(int, input().split())
ans = 2019
for i in range(L, R):
    for j in range(i, R + 1):
        ans = min(ans, i * j % 2019)
        if ans == 0: break

print(ans)
l, r = map(int, input().split())
dif = r - l
ans = 0
if dif >= 2019:
    ans = 0
else:
    mod_l = l % 2019
    mod_r = r % 2019
    if mod_l < mod_r:
        if 3 >= mod_l and mod_r >= 673:
            ans = 0
        else:
            ans = mod_l * (mod_l + 1)
    else:
        ans = 0
#print(dif, mod_l, mod_r)
print(ans%2019)
l,r = map(int,input().split())
ans = 2019

if l == 0:print(0);quit()

for i in range(l,r+1):
    if ans == 0:
        break
    ans = min(ans,i*(i+1)%2019)

print(ans)
l,r = map(int,input().split())
mn = 2018
if l >= 2019:
    mn = 0
else:
    for i in range(l,r):
        for j in range(l+1,r+1):
            mn = min(mn,i*j % 2019)
print(mn)
# AtCoder Beginner Contest 133
# C - Remainder Minimization 2019
L,R=map(int,input().split())

mod=2019
ans=10**18+7


for i in range (L,min(R,L+mod)):
    for j in range (L+1,min(R+1,L+mod+1)):
        tempans=(i%mod)*(j%mod)
        # print(i,j,tempans)
        if tempans<ans:
            ans=tempans
print(ans)
L,R = map(int,input().split())
ll, rr = L//2019, R//2019

if rr-ll>1: 
  print(0)
  exit(0)
  
for i in range(1, 2018):
  for j in range(ll,rr+1):
    l_, r_ = j*2019+i,j*2019+i+1
    if L<=l_ and r_<=R:
      print(((j*2019+i)*(j*2019+i+1))%2019)
      exit(0)
L,R = map(int,input().split())
ans = 4000

for i in range(L,R+1):
    i %= 2019
    for j in range(i+1,R+1):
        ans = min(ans,i*j%2019)
        if ans == 0:
            break
    else:
        continue
    break
print(ans)
def solve():
    L, R = map(int, input().split())
    
    if R-L+1 >= 2019:
        return 0
    
    list = [i % 2019 for i in range(L, R+1)]
    list.sort()
    return list[0] * list[1]

print(solve())
l,r=list(map(int,input().split()))
s=[]
import sys

if r-l>2050:
  print(0)
  sys.exit()
else:
  for i in range(l,r+1):
    s.append(i%2019)

n=len(s)
ans=30000
for i in range(n-1):
  for j in range(i+1,n):
    ans=min(ans,(i*j)%2019)

print(ans)
l, r = map(int, input().split())
la = int(l % 2019)
ra = int(r % 2019)
diff = int(ra - la)
if diff <= 0:
  print("0")
  exit()
ans = int(2019)
for i in range(la, ra):
  for j in range(i+1, ra+1):
    mul = int((i*j) % 2019)
    if mul <= ans:
      ans = mul
print(ans)
l,r=map(int,input().split())
s=10000
for i in range(l,r+1):
    if i%2019==0:
        s=0
        break
    elif (i%673==0 and r-l!=1) or (i%673==0 and (r%3==0 or l%3==0)):
        s=0
        break
if s==0:
    print(0)
else:
    print(((l%2019)*((l+1)%2019))%2019)
L, R = map(int, input().split())
rL = L % 2019
rR = R % 2019

if rL < rR and R-L < 2019:
    print(rL * (rL+1))
else:
    print(0)
l,r=map(int,input().split())
ll=2019*(l//2019)
rl=2019*(r//2019)
ans=0
if ll==rl:
  ans=(l%2019)*((l+1)%2019)
else:
  ans=0
print(ans)
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    l,r=pin()
    L=l%2019
    R=r%2019
    #print(L,R)
    if r-l>=2019 or R<=L:
        print(0)
        return
    
    else:print((L*(L+1))%2019)
#%%submit!
resolve()
l,r=map(int,input().split())
ans=2018
for i in range(l,r-1):
    for j in range(i+1,r):
        mod=(i*j)%2019
        if mod<ans: ans=mod
print(ans)
L,R = (int(x) for x in input().split())
Sort = sorted(x%2019 for x in range(L,min(L+2019,R+1)))[:2]
print(Sort[0]*Sort[1])
L,R = map(int,input().split())
a =[i for i in range(L,R+1)]
x = []
for i in a:
  
  if i%2019==0:
    print(0)
    exit()
  else:
    x.append(i%2019)
    
print(x[0]*x[1])
L,R = map(int, input().split())

if R-L==2019:
    print(0)
    exit()
    
min = 2020
for i in range(L,R+1):
    if min > i % 2019:
        min = i % 2019

print(min*(min + 1))
def solve():
    L, R = map(int, input().split())
    
    if R-L+1 > 2019:
        return 0
    
    list = [i % 2019 for i in range(L, R+1)]
    list.sort()
    return list[0] * list[1]

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

def mod(num):
    return num % 2019

l = mod(L)
r = mod(R)

if l > r or (R - L) > 2019:
    print(0)

else:
    print(min(mod(l * (l + 1)), mod((r - 1) * r)))
#!/usr/bin/env python
# coding: utf-8

# In[12]:


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


# In[17]:


if R//2019 - (L-1)//2019 > 0:
    print(0)
else:
    ans = 2018
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            ans = min(ans, (i*j)%2019)
            if ans == 1:
                break
        else:
            continue
        break
    print(ans)


# In[ ]:
a,b=map(int, input().split())
 
A = a%2019
B = b%2019
 
c = max(A,B)
d = min(A,B)
 
C = 2018
 
if A == 0 or B == 0 or A == B:
    print(0)
    exit()
else:
    for i in range(d,c):
        for j in range(i+1,c+1):
            C = min(C,i*j%2019)
print(C)
L, R = map(int, input().split())

reg = 10**9
if R-L >= 3000:
    print(0)
else:
    for l in range(L, R):
        for r in range(l+1, R+1):
            tmp = (l * r) % 2019
            reg = min(reg, tmp)
print(reg)
L, R = map(int, input().split())
if R-L >= 2018:
    print(0)
else:
    m = 10*100
    for i in range(L, R):
        for j in range(i+1, R+1):
            m = min(m, (i*j)%2019)

    print(m)
L, R = [int(i) for i in input().split()]
R = min(R, L + (2019 * 2))
diff = R - L
ans = 2019
if diff == 1:
    x = (L * (L + 1)) % 2019
    print(min(x, ans))
else:
    for i in range(diff):
        for j in range(i, diff):
            x = ((L + i) * (L + j)) % 2019
            ans = min(x, ans)
            if x == 0:
                break
    print(ans)
l,r=map(int,input().split())
i=l//2019
if 2019*i<l and r<2019*(i+1):
    d=list(range(l,r+1))
    d2=list(map(lambda x:x%2019,d))
    i=min(d2)
    d2.remove(i)
    j=min(d2)
    print(i*j)
else:
    print(0)
l,r=map(int,input().split())

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

if r//673 > (l-1)//673 and r//3 >(l-1)//3:
  print('0')

else:
    print((l%2019) * ((l+1)%2019) % 2019)
l, r = map(int, input().split())
mod = 2019
l_n = l//mod
r_n = r//mod
#print(l_n, r_n)
if l_n == r_n:
    print((l % mod)*((l+1) % mod) % mod)
elif l_n < r_n:
    print(0)
L, R = map(int, input().split())
ls = L // 2019
la = L % 2019
rs = R // 2019
ra = R % 2019
ans = 0
if ls == rs:
    ans = la * (la + 1)
elif rs - ls == 1:
    if ra == 0:
        ans = la
    else:
        ans = 0
else:
    ans = 0
print(ans)
l, r = [int(x) for x in input().split()]

l %= 2019
temp = r % 2019
r = temp if temp > l else temp + 2019

ans = 2019
for i in range(l, r):
    for j in range(i + 1, r + 1):
        temp = (i * j) % 2019
        if temp < ans:
            ans = temp
            if ans == 0:
                print(0)
                exit()
print(ans)
l,r = map(int,input().split())
x = l%2019
if l//673 < r//673 or l%673==0 and l//3 < r//3 or l%3==0:
    ans = 0
else:
    ans = l*(l+1)%2019
print(ans)
L, R = map(int, input().split())

count_limit = 0 # count limit is 2019
min_num = 2020
for i in range(L+1, R+1):
    min_num = min(min_num, (L*i)%2019)

    # limit process
    count_limit = count_limit + 1
    if count_limit>2019:
        break

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

if R-L>2019 or L>R :
    print(0)
    exit()
if L%2019+(R-L)>=2019 :
    print(0)
    exit()
l1=L%2019
r1=R%2019

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

print( ans )
l,r=map(int,input().split())
mod=2019
if r-l+1>=2019 or r%mod<l%mod:
    ans=0
else:
    ans=l*(l+1)%mod
print(ans)
L, R = map(int, input().split())

mini = min(L % 2019, R % 2019)
mini_sec = max(L % 2019, R % 2019)

for i in range(L + 1, R + 1):
    if i % 2019 < mini_sec:
        if i % 2019 < mini:
            mini_sec = mini
            mini = i % 2019
        else:
            mini_sec = i % 2019



print(mini * mini_sec)
l,r = map(int, input().split())
nums = []
if r - l >= 2019:
    ans = 0
else:
    for i in range(l, r+1):
        num = i % 2019
        nums.append(num)
    nums.sort()
    ans = (nums[0] * nums[1]) % 2019
print(ans)
import math
import collections
from operator import mul
from functools import reduce

L,R=map(int,input().split())
L%=2019
R%=2019
if L>=R:
    R+=2019

m=1000000000000000000;
for i in range(L,R):
    for j in range(i+1,R+1):
        m=min(m,((i%2019)*(j%2019))%2019)
print(m)
import math as m
A,B,C,D=map(int,input().split())
A-=1
g=C*D//m.gcd(C,D)
x=B//C-A//C
y=B//D-A//D
z=B//g-A//g
print(B-A-x-y+z)
import math
a,b,c,d=list(map(int,input().split()))
a-=1
def calculation(x,c,d):
	x=x-(x//c)-(x//d)+(x//((c*d)//math.gcd(c,d)))
	return x
	
print(calculation(b,c,d)-calculation(a,c,d))
import math
def lcm(x,y):
    return (x*y)//math.gcd(x,y)
a,b,c,d=map(int,input().split())
bc=b//c
bd=b//d
bcd=b//lcm(c,d)
x=b-(bc+bd-bcd)
a=a-1
ac=a//c
ad=a//d
acd=a//lcm(c,d)
y=a-(ac+ad-acd)
print(x-y)
import math

def main():
    A, B, C, D = map(int, input().split())
    lcm = C * D // math.gcd(C, D)
    C_div = B // C - (A - 1) // C
    D_div = B // D - (A - 1) // D
    C_D_div = B // lcm - (A - 1) //lcm
    print(B - A + 1 - C_div - D_div + C_D_div)


if __name__ == '__main__':
    main()
import fractions

A, B, C, D = (int(abcd) for abcd in input().split())
lcm_CD = C*D // fractions.gcd(C, D)
in_B = B - ((B//C + B//D) - B//lcm_CD)
in_under_A = (A-1) - (((A-1)//C + (A-1)//D) - (A-1)//lcm_CD)
print(in_B - in_under_A)
A, B, C, D = map(int, input().split())

def gcd(x, y):
    if y == 0: return x
    return gcd(y, x%y)

def lcm(x, y):
    return x * y // gcd(x, y)

# CとDの最大公約数
E = lcm(C, D)

F = 0
F += B // C + B // D - B // E
F -= (A - 1) // C + (A - 1) // D - (A - 1) // E

print(B - A + 1 - F)
from fractions  import gcd

def lcm(x, y):
  return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())

a_num = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d))
b_num = b - (b // c + b // d - b // lcm(c, d))

ans = b_num - a_num

print(ans)
def euclid(a, b):
  if b == 0:
    return a
  else:
    return euclid(b, a%b)
A,B,C,D=map(int,input().split())
if A%C==0:
  k=A//C
else:
  k=(A//C)+1
if B%C==0:
  t=B//C
else:
  t=(B//C)
n=t-k+1
if A%D==0:
  a=A//D
else:
  a=(A//D)+1
b=B//D
m=b-a+1
mi=(C*D)//euclid(C, D)
if A%(C*D)==0:
  c=A//mi
else:
  c=(A//mi)+1
d=(B//mi)
r=d-c+1
s=n+m-r
print(B-A+1-s)
import math
a,b,c,d = map(int,input().split()) 

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a-=1
e=lcm(c,d)

ansb=0
ansb += b//c
ansb += b//d
ansb -= b//e



ansa=0
ansa += a//c
ansa += a//d
ansa -= a//e
print((b-a)-(ansb-ansa))
from fractions import gcd

a, b, c, d = map(int, input().split())

div_c = b//c - a//c
if a%c == 0: div_c += 1
div_d = b//d - a//d
if a%d == 0: div_d += 1
lcm_cd = c*d//gcd(c, d)
div_cd = b//lcm_cd - a//lcm_cd
if a%lcm_cd == 0: div_cd += 1
print(b - a + 1 - div_c - div_d + div_cd)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

a, b, c, d = map(int, input().split())
g = gcd(c, d)
l = int(c*d/g)

print((b - a + 1) - ((b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//l - (a-1)//l)))
from fractions import gcd

A, B, C, D = map(int, input().split())
l = C * D // gcd(C, D)
x = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // l
y = B - B // C - B // D + B // l
print(y - x)
import math

a, b, c, d = list(map(int, input().split()))

ac = (a-1) // c
ad = (a-1) // d
bc = b // c
bd = b // d
cd_lcm =  (c * d) // math.gcd(c, d)
acd_lcm = (a-1) // cd_lcm
bcd_lcm = b // cd_lcm

l = b - a + 1

print(l - (bc - ac) - (bd - ad) + (bcd_lcm - acd_lcm))
import math
def lcm(x,y):
    return(x*y)//math.gcd(x,y)

a,b,c,d=map(int,input().split())
e=b//c-(a-1)//c
f=b//d-(a-1)//d

g=b//lcm(c,d)-(a-1)//lcm(c,d)
ans=e+f-g
#print(e,f,g)
print(b-a+1-ans)
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

A, B, C, D = map(int, input().split())
cnt = B - A + 1
all_range = B // C + B // D - B // lcm(C , D)
sub_end = A - 1
sub_range = sub_end // C + sub_end // D - sub_end // lcm(C , D)
print(cnt - (all_range - sub_range))
import sys
readline = sys.stdin.readline
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def main():
    A, B, C, D = map(int, readline().rstrip().split())
    ans = B - (B//C + B//D - B//lcm_base(C, D))
    ans -= ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm_base(C, D)))
    print(ans)

if __name__ == '__main__':
    main()
import fractions
a,b,c,d = map(int, input().split())

def lcm(a,b):
    return a * b // fractions.gcd(a, b)

def count(num, a, b):
    return int(num - num//a - num//b + num//lcm(a,b))

print(count(b,c,d)-count(a-1,c,d))
a,b,c,d = map(int,input().split())
total_num = b-a+1
# # of x%c==0
c_num = b//c - (a-1)//c
d_num = b//d - (a-1)//d
from fractions import gcd
lcm = c*d//gcd(c,d)
cd_num = b//lcm - (a-1)//lcm
print(total_num-c_num-d_num+cd_num)
#二回目
import fractions
a,b,c,d=map(int,input().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


ans1=b
a-=1
ans2=0
ans1-=b//c
ans1-=b//d

ans1+=b//(lcm(c,d))
#print(ans1)

ans2+=a//c
ans2+=a//d
ans2-=a//(lcm(c,d))
print(ans1-(a-ans2))
#!/usr/bin/env python3
import fractions


def main():
    A, B, C, D = map(int, input().split())

    num_C = B // C - (A - 1) // C
    num_D = B // D - (A - 1) // D
    lcm = C * D // fractions.gcd(C, D)
    num_CD = B // lcm - (A - 1) // lcm

    ans = (B - A + 1) - num_C - num_D + num_CD
    print(ans)


if __name__ == '__main__':
    main()
from fractions import gcd
a, b, c, d = map(int, input().split())
ans = b-a+1
lcm_cd = (c*d)//gcd(c, d)

under_a = (a-1)//c + (a-1)//d - (a-1)//lcm_cd
under_b = b//c + b//d - b//lcm_cd
print(ans-(under_b-under_a))
from fractions import gcd
a,b,c,d = map(int,input().split())
 
e = c*d//gcd(c,d)
A = (a-1)//c + (a-1)//d - (a-1)//e
B = b//c + b//d -b//e
print(b - a + 1 + A - B)
a,b,c,d = list(map(int, input().split()))

def num_fact_in(begin, end):
    def f(div):
        return end//div - (begin-1)//div
    return f

import math
lcm = c * d // math.gcd(c, d)

f = num_fact_in(a, b)
print(b - a + 1 - (f(c) + f(d) - f(lcm)))
from fractions import gcd
lcm = lambda a, b: a * b // gcd(a, b)
num_of_multi = lambda n: b // n - a // n - bool(a % n) + 1

a, b, c, d = map(int, input().split())
print(b - a + 1 - num_of_multi(c) - num_of_multi(d) + num_of_multi(lcm(c, d)))
from fractions import gcd
A,B,C,D=map(int,input().split())
A-=1
lcm=C*D//gcd(C,D)
print(B-B//C-B//D+B//lcm-(A-A//C-A//D+A//lcm))
from fractions import gcd
a,b,c,d=map(int,input().split())
e=c*d//gcd(c,d)#最小公倍数
sm=(b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//e-(a-1)//e)
print(int(b-a+1-sm))
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
def lcm(a, b):
    return a // gcd(a, b) * b

A, B, C, D = map(int, input().split())

L = lcm(C, D)

def f(X):
    return X - (X//C + X//D - X//L)

num = f(B) - f(A-1)

print(num)
from fractions import gcd
a, b, c, d = map(int, input().split())
e = b//c - (a-1)//c
f = b//d - (a-1)//d
def lcm(x, y):
	return (x * y) // gcd(x, y)
g = lcm(c, d)
h = b//g - (a-1)//g

print (b-a+1 -(e+f-h))
#!/usr/bin/env python3

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())

N = B - A + 1

g = lcm(C,D)
C_ = B//C - (A-1)//C
D_ = B//D - (A-1)//D
CD_ = B//g - (A-1)//g
ans = N - C_ - D_ + CD_
print(ans)
A,B,C,D = map(int, input().split())
from fractions import gcd

cd = C*D//gcd(D,C)
f = lambda x: B//x - ((A-1)//x)
print(B - A + 1 - (f(C) + f(D) - f(cd)))
from fractions import gcd
def lcm(x,y):
    return (x * y) // gcd(x,y)

A,B,C,D = map(int,input().split())

cnt = 0
cnt += ((B // C) - ((A-1) // C))
cnt += ((B // D) - ((A-1) // D))

tmp = ((B//lcm(C,D)) - ((A-1)//lcm(C,D)))

ans = B-A+1-cnt+tmp
print(ans)
A, B, C, D = map(int, input().split())

def gcd(a, b):
    if (b==0):
        return a
    else:
        return gcd(b, a % b)

G = C * D // gcd(C, D)

ans_b = B - B//C - B//D + B//G
ans_a = A - 1 - (A-1)//C - (A-1)//D + (A-1)//G

print(ans_b - ans_a)
from fractions import gcd
a,b,c,d=map(int,input().split())
e=c*d//gcd(c,d)
def num(x,c,d,e):
  return x-x//c-x//d+x//e
print(num(b,c,d,e)-num(a-1,c,d,e))
from fractions import gcd
a,b,c,d = map(int, input().split())
def f(p):
  if a % p ==0:
    return(b//p - a//p + 1)
  else:
    return(b//p - a//p)
  
print(b-a+1 - (f(c)+f(d) - f(int(c*d/gcd(c,d)))))
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools
 
def solve():
  a, b, c, d = map(int, input().split())
  a -= 1
  lc = (c*d)//fractions.gcd(c,d)
  ans = (b-a)-(b//c-a//c)-(b//d-a//d)+(b//lc-a//lc)
  print(ans)
  return 0
 
if __name__ == "__main__":
  solve()
import math

a, b, c, d = map(int, input().split())

gcd = (c * d) // math.gcd(c, d)

r = b // c + b // d - b // gcd
l = (a - 1) // c + (a - 1) // d - (a - 1) // gcd

print((b - a) - (r - l) + 1)
import math
def lcm(x, y): # 最小公倍数
    return (x * y) // math.gcd(x, y)


a, b, c, d = map(int, input().split())

lcm_cd = lcm(c, d)

under_b = b - b//c - b//d + b//lcm_cd
over_a = (a-1) - (a-1)//c - (a-1)//d + (a-1)//lcm_cd

print(under_b - over_a)
import fractions

A,B,C,D = map(int, input().split())

def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)

a = (B // C) - ((A-1) // C)
b = (B // D) - ((A-1) // D)
c = (B // (lcm(C, D))) - ((A-1) // (lcm(C, D)))

s = a + b - c

ans = B - (A-1) - s

print(ans)
from fractions import gcd
a, b, c, d = list(map(int, input().split()))

c_cnt = b // c  - (a-1) // c
d_cnt = b // d  - (a-1) // d

lcm = c * d // gcd(c, d)
lcm_cnt = b // lcm  - (a-1) // lcm

print((b - a + 1) - (c_cnt + d_cnt - lcm_cnt))
A, B, C, D = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

lcm = C * D // gcd(C, D)

def get_num(X):
    num_c = X // C
    num_d = X // D
    common = X // lcm
    return X - (num_c + num_d) + common


print(get_num(B) - get_num(A - 1))
def main():
    import fractions
    a,b,c,d=map(int, input().split())
    def lcm(c,d):
        return c*d//fractions.gcd(c,d)
    e=lcm(c,d)
    ans=(b-a+1)-((b//c-(a-1)//c)+(b//d-(a-1)//d))+(b//e-(a-1)//e)
    print(ans)
    
if __name__=='__main__':
    main()
from fractions import gcd
a,b,c,d = map(int,input().split())
a = a-1
l = int(c*d/gcd(d,c))
cn = b//c-a//c
dn = b//d-a//d
ln = b//l-a//l
ans = b-a-cn-dn+ln
print(ans)
import math

A, B, C, D = map(int, input().split())

cd = (C * D) // math.gcd(C, D)

pac, qac = divmod(A, C)
pad, qad = divmod(A, D)
pacd, qacd = divmod(A, cd)

pbc, qbc = divmod(B, C)
pbd, qbd = divmod(B, D)
pbcd, qbcd = divmod(B, cd)

pac = pac - 1 if qac == 0 else pac
pad = pad - 1 if qad != 0 else pad
pacd = pacd - 1 if qacd != 0 else pacd

ans = (pbc + pbd - pbcd) - (pac + pad - pacd)
print(B - A - ans + 1)
a,b,c,d = map(int,input().split())

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def f(e):
   return e - (e//c + e//d - e//(c*d//gcd(c,d)))

print(f(b)-f(a-1))
from math import gcd
A, B, C, D = map(int, input().split())

if C == 1 or D == 1:
    print(0)
    exit()

def check(A, B, x):
    return B//x - (A-1)//x

print((B - A + 1) - (check(A, B, C) + check(A, B, D) - check(A, B, C*D//gcd(C, D))) )
import math
a, b, c, d = list(map(int, input().split()))

a_div_c = (a-1) // c
a_div_d = (a-1) // d
a_div_cd = (a-1) // (c * d // math.gcd(c, d))
b_div_c = b // c
b_div_d = b // d
b_div_cd = b // (c * d // math.gcd(c, d))

y = b - (b_div_c + b_div_d - b_div_cd)
x = (a - 1) - (a_div_c + a_div_d - a_div_cd)

print(y-x)
a,b,c,d=map(int,input().split())

from fractions import gcd
m=(c*d)//gcd(c,d)

A=b//c-(a-1)//c # a-bのうち、cの倍数のもの
B=b//d-(a-1)//d # a-bのうち、dの倍数のもの
C=b//m-(a-1)//m # a-bのうち、cとdの最小公倍数の倍数のもの
ans=(b-a+1)-(A+B-C)
print(ans)
from fractions import gcd
A, B, C, D = map(int, input().split())

def lcm(x, y):
    return (x * y) // gcd(x, y)

C_count = B // C - A // C
if A % C == 0:
    C_count += 1
D_count = B // D - A // D
if A % D == 0:
    D_count += 1
CD_count = B // lcm(C, D) - A // lcm(C, D)
if A % lcm(C, D) == 0:
    CD_count += 1
div_count = C_count + D_count - CD_count
ans = B - A + 1 - div_count
print(ans)
A, B, C, D = map(int, input().split())

def gcd(a, b):
    if a == 0:
        return b
    return int(gcd(b%a, a))

def lcm(a, b):
    return int(a * b / gcd(a, b))

E = lcm(C, D)
ans = (B-A+1) - (B//C - (A-1)//C) - (B//D - (A-1)//D) + (B//E - (A-1)//E)

print(ans)
A, B, C, D = map(int, input().split())
def div_num(a, b, c):
    if (a%c)==0:
        return (b//c)-(a//c)+1
    else:
        return (b//c)-(a//c)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
XC = div_num(A, B, C)
XD = div_num(A, B, D)
XCD = div_num(A,B,int((C*D)/gcd(C,D)))
print(B-A+1-(XC+XD-XCD))
A, B, C, D = map(int, input().split())

c = C
d = D

gcd = 0
while gcd == 0:
  if c > d:
    k = c
    c = d
    d = k # 必ず c <= d になる
  if d%c == 0:
    gcd = c
  else:
    d = d%c

# 最小公倍数（lcm）
lcm = int(C*D/gcd)

wareru = B//C + B//D - B//lcm - (A-1)//C - (A-1)//D + (A-1)//lcm
ans = B-A+1-wareru
print(ans)