peterverebics/CodeNet_Python_118 huggingface dataset:
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
A, B, C, D = list(map(int, input().split()))

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


# b以下での個数
cb = B//C
db = B//D
cdb = B//(lcm(C, D))
total_b = cb+db-cdb

# a以下での個数
A -= 1
ca = A//C
da = A//D
cda = A//(lcm(C, D))
total_a = ca+da-cda

# print(total_a)
# print(total_b)
t = int(B-A)
s = int(total_b-total_a)
print(t-s)
import fractions

a,b,c,d= map(int,input().split())
x = (b//c)-((a-1)//c)
y = (b//d)-((a-1)//d)
lcm = (c*d)//fractions.gcd(c,d)
z = (b//lcm)-((a-1)//lcm)

print(b-a-x-y+z)
a,b,c,d = map(int,input().split())
ac = (a-1)//c
bc = b//c
ad = (a-1)//d
bd = b//d
ans1 = bc-ac
ans2 = bd-ad
print((b-a)-max(ans1,ans2))
import math


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

    print(b-a-(math.floor((b - a) / c) +
               math.floor((b - a) / d) - math.floor((b - a) / (c*d/math.gcd(c, d)))))


if __name__ == "__main__":
    main()
from math import floor
from fractions import gcd

A, B, C, D = map(int,input().split())
lcm = (C*D) // gcd(C,D)

bc = floor(B / C)
bd = floor(B / D)
bcd = floor(B / lcm)

ac = floor((A-1) / C)
ad = floor((A-1) / D)
acd = floor((A-1) / lcm)

ans = B-bc-bd+bcd-(A-1-ac-ad+acd)
print(ans)
import math
a,b,c,d = map(int, input().split())
n = b-a+1
x = c*d//math.gcd(c,d)
c_cnt =  b//c - (a-1)//c
d_cnt = b//d - (a-1)//d

print(n - c_cnt - d_cnt + b//x)
import math
a, b, c, d = list(map(int, input().split()))

cnt = 0
numc = math.floor(b/c) - math.ceil(a/c) + 1
numd = math.floor(b/d) - math.ceil(a/d) + 1

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

cd = (c*d) // gcd(c, d)
numcd = math.floor(b/cd) - math.ceil(a/cd) + 1

cnt = b - a + 1 - numc - numd + numcd
import math
A,B,C,D = map(int,input().split())
count = 0
x = math.ceil((B/C)-(A/C))
y = math.ceil((B/D)-(A/D))
z = math.ceil((B/(C*D))-(A/(C*D)))

if A%C == 0:
  x += 1
if A%D == 0:
  y += 1
if A%(C*D) ==0:
  z += 1

ans = B-A+1 -(x+y-z)
print(ans)
a,b,c,d = map(int,input().split())
cd = c * d
n_c = 0
n_d = 0
n_cd = 0
i = ( a // c  ) + c
while i <= b:
    n_c += 1
    i += c
i = ( a // d) + d
while i <= b:
    n_d += 1
    i += d
i = ( a // cd ) + cd
while i<= b:
    n_cd += 1
    i+=cd
print(b-a+1-(n_c+n_d-n_cd))
import fractions
a,b,c,d = map(int,input().split())
num = b-a+1
ac = int((a-1)//c)
ad = int((a-1)//d)
bc = int(b//c)
bd = int(b//d)
e = c*d//(fractions.gcd(c,d))
a = int(a//e)
b = int(b//e)
c = bc-ac
d = bd-ad
e = b-a
print(num-(c+d-e))
import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d/math.gcd(c,d)) - (a-1)//(c*d/math.gcd(c,d))
s12=int(s12)
#print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))
w,h,x,y = map(int, input().split())
if abs(2*x-w) == abs(2*y-h):
    print(h*w/2,1)
else:
    print(w*h/2,0)
A,B,C,D = map(int,input().split())

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

s = lcm(C,D)
X =  A - (A//C + A //D - A//s)
Y =  B - (B//C + B //D - B//s)
print(Y-X)
A,B,C,D=map(int,input().split())
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
def lcm(a,b):
  return (a*b)//gcd(a,b)
def main(a,b,c):
  if a%c==0 or b%c==0:
    s=((b-a)//c)+1
  else:
    s=(b-a)//c
  return s
S=main(A,B,C)
T=main(A,B,D)
U=main(A,B,lcm(C,D))
V=S+T-U
print(B-A+1-V)
from fractions import gcd

a, b, c, d = list(map(int, input().split()))
#b = list(map(int, input().split()))
total = b-a+1
lcm = int((c*d)/gcd(c, d))

d1 = b//c - a//c
d2 = b//d - a//d
add = b//lcm - a//lcm
if a % c == 0:
    d1 += 1
if a % d == 0:
    d2 += 1

print(total-d1-d2+add)
from fractions import gcd

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

a,b,c,d = map(int,input().split())
all = b - a + 1
if c == 1 or d == 1:
    print(0)
    exit()

cd = lcm(a, b)

cs = b//c - a//c + 1
ds = b//d - a//d + 1
cds = b//cd - a//cd + 1

print(all - cs - ds + cds)
from fractions import gcd
A,B,C,D=map(int,input().split())

rc=(B//C)-((A-1)//C)#割り切れる数
rd=(B//D)-((A-1)//D)#割り切れる数

rcd=(B//(C*D/gcd(C,D)))-((A-1)//(C*D/gcd(C,D)))
print(int((B-A+1)-(rc+rd-rcd)))
import math
a,b,c,d = map(int,input().split())
e = c*d/math.gcd(c,d)
print(b-a+1 + (math.floor(b/e)-(math.ceil(a/e))+1)-(math.floor(b/c)-(math.ceil(a/c))+1)-(math.floor(b/d)-(math.ceil(a/d))+1))
from math import gcd
a, b, c, d = map(int,input().split())
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(c, d)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(int(g))
import math
import fractions
EPS = 1e-5

def ceil(x):
    return math.ceil(x - EPS)
def floor(x):
    return math.floor(x + EPS)

def countX(X) :
    if X > B :
        return 0
    minX = ceil(A / X)
    maxX = floor(B / X)

    return maxX - minX + 1

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

ans = B - A + 1

# 最小公倍数
Z = C * D // fractions.gcd(C,D)

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

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


def calc(n, div_1, div_2):
    cnt = 0
    cnt += n // div_1
    cnt += n // div_2
    cnt -= int(n / (div_1 * div_2 / gcd(div_1, div_2)))
    return n - cnt


print(calc(b, c, d) - calc(a-1, c, d))
import fractions

A,B,C,D = list(map(int, input().split()))
cc = int(B/C) - int((A-1)/C)
dd = int(B/D) - int((A-1)/D)
cd = C*D / fractions.gcd(C,D)
ee = int(B/(cd)) - int((A-1)/(cd))
U = B-A+1
print(U - (cc + dd - ee))
a, b, c, d = map(int, input().split())
ans = b - a + 1
x = b // c - a // c
if a % c == 0:
    x += 1
x += b // d - a // d
if a % d == 0:
    x += 1
x -= b // (c * d) - a // (c * d)
if a % (c * d) == 0:
    x -= 1
ans -= x
print(ans)
from fractions import gcd
a,b,c,d=map(int,input().split())
count=b-a+1
temp1=b//c-(a-1)//c
temp2=b//d-(a-1)//d
temp3=b//((c*d)/gcd(c,d))-(a-1)//((c*d)/gcd(c,d))
print(int(count-temp1-temp2+temp3))
from fractions import gcd
a,b,c,d = map(int,input().split())
def l(x,y):
    return (x*y)//gcd(x,y)
U = b-a+1
s1 = b//c - (a-1)//c
s2 = b//d - (a-1)//d
s3 = b//l(a,b) - (a-1)//l(a,b)
print(U-(s1+s2-s3))
import math

A,B,C,D = map(int, input().split())
a = B//C - math.ceil(A/C) + 1
b = B//D - math.ceil(A/D) + 1
lcm = C*D//math.gcd(C,D)
c = B//lcm - math.ceil(A/lcm) + 1
print(B-(A-1)-(a+b-c))
def main():
    import fractions 
    import math
    a,b,c,d = map(int,input().split())
    m = int(c*d/fractions.gcd(c,d))
    c_=math.ceil(a/c)*c
    d_=math.ceil(a/d)*d
    c__ = math.floor(b/c)*c
    d__ = math.floor(b/d)*d
    m_ = math.ceil(a/m)*m
    m__ = math.floor(b/m)*m
    print(int(b-a-((c__-c_)//c+(d__-d_)//d-(m__-m_)//m)))

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

A,B,C,D = map(int,input().split())
A -= 1
g = fractions.gcd(C, D)
l = C * D / g

sA = A // C
eA = A // D
lA = A - (eA + sA - A // l)

sB = B // C
eB = B // D
lB = B - (eB + sB - B // l)
print(int(lB - lA))
import fractions

a,b,c,d = map(int, input().split())
#print(a,b,c,d)
l = 0
for i in range(a,b+1):
    l += 1

#print(l)
lcm = c*d / fractions.gcd(c,d)
    
print(int(l - l//c -l//d + l//lcm))
from fractions import gcd
a, b, c, d = map(int, input().split())
def quo_items(x, num1, num2):
    num1_quo = int(x // num1)
    num2_quo = int(x // num2)
    num12_quo = int(x // (num1 * num2 / gcd(num1, num2)))
    items = x - num1_quo - num2_quo + num12_quo
    return items

print(int(quo_items(b, c, d) - quo_items(a - 1, c, d)))
def main2():
    a, b, c, d = list(map(int, input().split()))

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    di = 0
    for i in range(d, a, d):
        if i % d == 0:
            di = i
            break
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()
from fractions import gcd
A, B, C, D = map(int, input().split())
cnt_C = int(B // C) - int((A-1) // C)
cnt_D = int(B // D) - int((A-1) // D)
cnt_CD = int(B // ((C*D)/gcd(C,D))) - int((A-1) // ((C*D)/gcd(C,D)))
print(B - A + 1 - (cnt_C + cnt_D - cnt_CD))
A, B, C, D = map(int, input().split())
def anti(A, B, m):
  ans = (B-A+1)//m
  mo = (B-A+1)%m
  if mo != 0 and mo > A%m:
    ans += 1
  return ans

import fractions
g = fractions.gcd(C,D)
h = int((C*D)//g)
x = anti(A,B,C)
y = anti(A,B,D)
z = anti(A,B,h)
ans = B-A+1-x-y+z
print(ans)
from fractions import gcd
a,b,c,d = map(int, input().split())

nums = b-a+1
t1 = b//c - a//c
t2 = b//d - a//d

lcm = (c*d)//gcd(c,d)
t3 = b//lcm - a//lcm
print(nums-t1-t2+t3)
import math
def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A,B,C,D = map(int,input().split())
minCg = math.ceil(A/C)
maxCg = math.floor(B/C)
minDg = math.ceil(A/D)
maxDg = math.floor(B/D)
gcd = gcd(C,D) 
CD = (C*D) // gcd
minCDg = math.ceil(A/(CD))
maxCDg = math.floor(B/(CD))
Cg = maxCg - minCg +1
Dg = maxDg - minDg +1
CDg = maxCDg - minCDg +1
Anti = (Cg+Dg-CDg)
print(B-A+1-Anti)
a,b,c,d = map(int,input().split())
e = c*d
h = b-a+1
print(h-(h//c+h//d-h//e))
a,b,c,d=map(int,input().split())
cwari=b//c-(a-1)//c
dwari=b//d-(a-1)//d
cdwari=b//(c*d)-(a-1)//(c*d)
ans=(b-a)+1-cwari-dwari+cdwari
print(ans)
import fractions
a,b,c,d=map(int,input().split())
a=a-1
l=c*d/fractions.gcd(c,d)
B=b-((b//c)+(b//d)-(b//l))
A=a-((a//c)+(a//d)-(a//l))
print(int(B-A))
import sys
import os
import fractions

MOD = 10 ** 9 + 7


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = list(map(int, sys.stdin.readline().split()))
    E = B - A + 1

    ret = 0
    ret += B // C
    ret += B // D
    ret -= (A - 1) // C
    ret -= (A - 1) // D
    ret -= B // lcm(C, D)
    print(E - ret)


if __name__ == '__main__':
    main()
A, B, C, D = map(int,input().split())
print(B - A + 1 - ((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // (C * D) - (A - 1) // (C * D))))
a, b, c, d = map(int, input().split())

def cnt(a, b, n):
  be = a//n
  if a%n:
    be+=1
  en = b//n
  return en-be+1

print(cnt(a, b, c)+cnt(a, b, d)-cnt(a, b, c*d))
import fractions
C, D, A, B  = map(int,input().split())
num = A * B // fractions.gcd(A, B)
ans = D - C + 1 - D // A + (C - 1) // A - D // B + (C - 1) // B + D // num - C // num

print(ans)
a,b,c,d=map(int,input().split())
a-=1
e=b//c-a//c
f=b//d-a//d
g=b//(c*d)-a//(c*d)
print(b-a-e-f+g)
#35 C - Anti-Division
import math
A,B,C,D = map(int,input().split())

# C と D の最小公倍数の個数
lcm = C*D//math.gcd(C,D)
cnt_lcm = B//lcm - A//lcm

# C の倍数の個数
cnt_C = B//C - (A-1)//C 

# D の倍数の個数
cnt_D = B//D - (A-1)//D

# (範囲内の整数) - (C の倍数 + D の倍数 - C,D の公倍数)
ans = (B - A + 1) - (cnt_C + cnt_D - cnt_lcm)
print(ans)
a, b, c, d = map(int, input().split())

def lcm(m, n):
    from fractions import gcd
    return (m * n) // gcd(m, n)

cd = lcm(c, d)

b_c = b//c
b_d = b//d
b_cd = b//cd
bb = b - (b_c + b_d - b_cd)

a_c = a//c
a_d = a//d
a_cd = a//cd
aa = a - (a_c + a_d - a_cd)

print(bb-aa)
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
A,B,C,D=map(int,input().split())
c=C*D/gcd(C,D)
b=B//C+B//D-B//c
a=(A-1)//C+(A-1)//D-(A-1)//c
print(int((B-b)-(A-1-a)))
from math import gcd
a,b,c,d=list(map(int,input().split()))

def calculation(x,c,d):
	x-=x//c
	x-=x//d
	x+=x//((c*d)//gcd(c,d))
	return x
	
print(calculation(b,c,d)-calculation(a,c,d))
a,b,c,d=map(int,input().split())
print(b-a+1-(b//c+b//d-b//(c*d)-((a-1)//c+(a-1)//d-(a-1)//(c*d))))
import fractions
a,b,c,d = map(int, input().split())

x = c*d/fractions.gcd(c,d)
A = (a-1) - (a-1)//c - (a-1)//d +x
B = b - (b-1)//c - (b-1)//d +x
print(int(B-A))
import numpy as np

def LI():
  return [int(s) for s in input().split()]

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

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

A,B,C,D = LI()

def can_divided(a,b,x):
    ret = (b - a) // x
    if b % x != 0:
      ret+=1
    if a % x != 0:
      ret+=1
    return ret
  
E = lcm(C,D)

total = can_divided(A,B,C)+can_divided(A,B,D)-can_divided(A,B,E)

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

lcm = lambda x, y: x*y // gcd(x, y)

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

b_ = b
b_ -= b // c
b_ -= b // d
b_ += b // lcm(c, d)

a_ = a - 1
a_ -= a // c
a_ -= a // d
a_ += a // lcm(c, d)


print(b_ - a_)
import math

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

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

num = b-a
c_1 = (b-a)//c
d_1 = (b-a)//d
cd_1 = (b-a)//(lcm)

ans = num - (c_1 + d_1) + cd_1
print(int(ans))
import fractions
a,b,c,d=map(int,input().split())
g=fractions.gcd(c,d)
l=int(c*d/g)
x=b-a
cl=a//c
cg=b//c
dl=a//d
dg=b//d
ll=a//l
lg=b//l
print(cl,cg,dl,dg,lg,ll)
r=int(x+1-(cg-cl+dg-dl-lg+ll))
print(r)
import sys
input = sys.stdin.readline
def main():
    A, B, C, D = map(int, input().split())
    N = B-A+1
    NC = (N+C-1)//C
    ND = (N+D-1)//D
    NCD = (N+C*D+1)//(C*D)
    ans = N - NC - ND + NCD

    print(ans)

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

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

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

    g = lcm(c,d)
    res = 0
    cmod = b//c - a//c
    dmod = b//d - a//d
    cdmod = b//g - a//g
    print(b-a+1-cmod-dmod+cdmod)
    
if __name__ == '__main__':
    main()
a, b, c, d = map(int, input().split())

a_c = (a - 1) // c
b_c = b // c
a_d = (a - 1) // d
b_d = b // d
a_cd = (a - 1) // (c * d)
b_cd = b // (c * d)

ans = (b - a + 1) - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd)

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

cnt = 0
numc = math.floor(b/c) - math.ceil(a/c) + 1
numd = math.floor(b/d) - math.ceil(a/d) + 1

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

cd = (c*d) // gcd(c, d)
numcd = math.floor(b/cd) - math.ceil(a/cd) + 1

cnt = b - a + 1 - numc - numd + numcd

print(cnt)
#abc133 c
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 int(x*y/gcd(x,y))

e=lcm(c,d) #c,dの最小公倍数


n=b-a+1
nc=int(b/c)
nd=int(b/d)
ne=int(b/e)
if a!=1:
    nc-=int((a-1)/c)
    nd-=int((a-1)/d)
    ne-=int((a-1)/e)


nf=nc+nd-ne#cまたはdの個数

ans=n-nf
print(ans)
a,b,c,d = map(int,input().split())
from fractions import gcd
cd_gcd = gcd(c,d)
lcm= c*d // cd_gcd


ans = []
for i in (a,b):
  ans.append(int(i/c) + int(i/d) - int(i/lcm))

print(b-a - (ans[1]-ans[0]) + 1)
from math import gcd as gcd
a, b, c, d = map(int,input().split())
#cでわれるもの
s = gcd(c, d)
p = c / s * d 
divide_c = b // c - (a - 1) // c
divide_d = b // d - (a - 1) // d
divide_cd = b // p - (a - 1) // p
print(int(b - a + 1 - divide_c - divide_d + divide_cd))
A,B,C,D=map(int,input().split())
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)
s=(B-A)//C
t=(B-A)//D
u=(B-A)//lcm(C,D)
v=s+t-u
print(B-A+1-u)
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))
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (((b)//c)-((a-1)//c))+(((b)//d)-((a-1)//d))- (((b)//(lc))-((a-1)//(lc)))
	print((b-(a-1))-cnt)
	

main()
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    A -= 1
    lcm = C * D / fractions.gcd(C, D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = B - (Bc + Bd - Blcm)

    Ac = int(A / C)
    Ad = int(A / D)
    Alcm = int(A / lcm)
    Adec = A - (Ac + Ad - Alcm)

    print(Bdec - Adec)


main()
a,b,c,d = map(int,input().split())
e = b - a
f = int(e/c)
g = int(e/d)
h = int(e/(c*d))
print(e-(f+g-h))
import fractions

a,b,c,d = map(int, input().split())
x = (b//c - (a - 0.1)//c)
y = (b//d - (a - 0.1)//d)
z = (b//((c * d)//fractions.gcd(c,d)) - (a - 0.1)//((c * d)//fractions.gcd(c,d)))

print(int((b - a + 1) - (x + y - z)))
import math
a,b,c,d=map(int,input().split())
x=b//c-a//c
y=b//d-a//d
g=math.gcd(c,d)
l=c*d//g
z=b//l-a//l
print(b-a+1-x-y+z)
from fractions import gcd
a, b, c, d = map(int, input().split())
def quo_items(x, num1, num2):
    num1_quo = x // num1
    num2_quo = x // num2
    num12_quo = x // (num1 / gcd(num1, num2) * num2)
    items = x - num1_quo - num2_quo + num12_quo
    return items

print(quo_items(b, c, d) - quo_items(a - 1, c, d))
a,b,c,d = map(int,input().split())

a_c = (a-1) // c
b_c = b // c
a_d = (a-1) // d
b_d = b // d
a_cd = (a-1) // (c*d)
b_cd = b // (c*d)

ans = (b-(a-1)) - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd)

print(ans)
import math

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

a = math.floor(B / C) - math.floor((A-1) / C)
b = math.floor(B / D) - math.floor((A-1) / D)
c = math.floor(B / (C*D)) - math.floor((A-1) / (C*D))

s = a + b - c

ans = B - (A-1) - s

print(ans)
import math
A,B,C,D = list(map(int,input().split()))

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

CD = lcm(C,D)

CD1 = (A//CD +1)*CD

kyoutuu = (B-CD1)//CD

C1 = (A//C + 1)*C
Cnum = (B - C1)//C

D1 =(A//D +1)*D
Dnum = (B - D1)//D

print(B-A-Cnum-Dnum+kyoutuu)
import sys
input = sys.stdin.readline
def main():
    A, B, C, D = map(int, input().split())
    N = B-A+1
    NC = (N+C-1)//C
    ND = (N+D-1)//D
    NCD = (N+C*D+1)//(C*D)
    ans = N - NC - ND + NCD
    print(N, NC, ND, NCD)
    print(ans)

if __name__ == '__main__':
    main()
A,B,C,D = map(int,input().split())
all_count = B-A
c_count = all_count//C
d_count = all_count//D
ans = all_count - c_count - d_count
print(ans)
A,B,C,D = map(int,input().split())

print(int(B // C - A // C + B // D - A // D + B // C*D - A // C*D  ))
import math
A, B, C, D = map(int, input().split())
 
# CでもDでも割り切れない = 全体(a) - Cで割り切れる(b) + Dで割り切れる(c) + CでもDでも割り切れる(d)
lcm = C*D // math.gcd(C, D)
a = B-A+1

if A % C != 0 and B % C != 0: b = a // C
else: b = a // C + 1
if A % D != 0 and B % D != 0: c = a // D
else: c = a // D + 1
if A % lcm != 0 and B % lcm != 0: d = a // lcm
else: d = a // lcm + 1

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

ans_lt_b = b - (b // c + b // d - b // (c * d))
ans_lt_a = (a - 1) - (((a - 1) // c) + ((a - 1) // d) + ((a - 1) // (c * d)))
print(ans_lt_b - ans_lt_a)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def gcd(a, b):
    # a,bの最大公約数D
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    # a,bの最小公倍数
    return a * b // gcd(a, b)


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

    all = B - A + 1
    c = -(-all // C)
    d = -(-all // D)
    cd = -(-all // lcm(C, D))

    print(all - c - d + cd)


if __name__ == "__main__":
    main()
from fractions import gcd
a,b,c,d = map(int,input().split())
cab = (b//c)-((a-1)//c)
dab = (b//d)-((a-1)//c)
lcm = int(c*d/gcd(c,d))
cdab = (b//lcm)-((a-1)//lcm)
print((b-a+1)-cab-dab+cdab)
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 - A//C - A//D + A//G

print(ans_b - ans_a + 1)
A, B, C, D = map(int, input().split())
min = min(C, D)
max = max(C, D)
c=0
d=0
e=0

def gcd(max, min):
  while min:
    max, min = min, max%min
  return max
lcm = max*min//gcd(max,min)
c = B//C-A//C
d = B//D-A//D
if lcm <= A:
  e = B//lcm-(-(-A//lcm))
else:
  e = B//lcm
print(c)
print(d)
print(e)

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

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

print(b-a+1-int(b//c)+int((a-1)//c)-int(b//d)+int((a-1)//d)+int(b//l)-int((a-1)//l))
import fractions
a,b,c,d=map(int,input().split())
g=fractions.gcd(c,d)
l=int(c*d/g)
x=b-a
cd=x//c
dd=x/d
ld=x//l

r=int(x-(cd+dd-ld))
print(r)
import fractions
def anti_division(a, b, c, d):

    ans = b-a+1
    cd = a*b // fractions.gcd(a, b)
    ccount = ((b+c)//c) - ((a+c)//c)
    dcount = ((b+d)//d) - ((a+d)//d)
    cdcount = ((b+cd)//cd) - ((a+cd)//cd)
    return ans-ccount-dcount+cdcount
def main():
    a, b, c, d = map(int, input().split())
    print(anti_division(a, b, c, d))

if __name__ == '__main__':
    main()
# AtCoder Beginner Contest 131
# C - Anti-Division
import math

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

A,B,C,D=map(int,input().split())
bc=B//C
ac=A//C
cnum=bc-ac

bd=B//D
ad=A//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=A//lcmcd
lcmcdnum=blcmcd-alcmcd


if lcm(C,D)==C*D:
    print(B-A-cnum-dnum+lcmcdnum)
else:
    print(B-A-cnum-dnum+lcmcdnum +1)
a,b,c,d=map(int,input().split())

zen=a-1
ack=int(zen//c)
adk=int(zen//d)
acdk=int(zen//(c*d))

aans=zen-ack-adk+acdk

ck=int(b//c)
dk=int(b//d)
cdk=int(b//(c*d))

ans=b-ck-dk+cdk

ans=ans-aans

print(ans)
import fractions
a,b,c,d = map(int,input().split())
l = (c*d)//fractions.gcd(c,d)
if fractions.gcd(c,d) == 1:
	l = 10**18+1
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))
	print(b-a-(num2-num))
else:
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))-1
	print(b-a-(num2-num))
import math
a,b,c,d = map(int,input().split())
e = int(c*d/math.gcd(c,d))
wa = 0
c_seki = int(b/c)-int((a-1)/c)
d_seki = int(b/d)-int((a-1)/d)
e_seki = int(b/e)-int((a-1)/e)
wa = c_seki+d_seki-e_seki
print(b-a+1-wa,c_seki,d_seki,e_seki)
a, b, c, d = map(int, input().split())
print((b-a+1) - (b//c + b//d - b//(c*d)) + ((a-1)//c + (a-1)//d - (a-1)//(c*d)))
# https://atcoder.jp/contests/abc131/tasks/abc131_c

from fractions import gcd


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

C_ = (B // C) - ((A - 1) // C)

D_ = (B // D) - ((A - 1) // D)

# 最大公約数
CD = gcd(C, D)

# 最小公倍数
CD = (C * D) / CD

CD_ = (B // CD) - ((A - 1) // CD)

total_num = B - (A - 1)

ans = total_num - C_ - D_ + CD_

print(int(ans))
import fractions
def lcm(x,y):
    return (x * y) // fractions.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 = 0
tmp = ((B//lcm(C,D)) - (A//lcm(C,D)))

print(B-A+1-cnt+tmp)
import fractions
a,b,c,d= map(int,input().split())
n = b-a+1#要素数
j = b//c + b//d - (a-1)//c - (a-1)//d#a~bの範囲でcで割りきれる数とdで割り切れる数の合計
lcm =(c*d) / fractions.gcd(c,d)#c,dの最小公倍数
print(int(n-j-(b//lcm-(a-1)//lcm)))
from math import ceil
from fractions import gcd

a, b, c, d = map(int, input().split())
cd_lcm = c*d//gcd(c, d)
c_left, c_right = ceil(a/c), b//c
d_left, d_right = ceil(a/d), b//d
cd_left, cd_right = ceil(a/cd_lcm), b//(cd_lcm)
cv, dv, cdv = c_right - c_left + 1, d_right - d_left + 1, cd_right - cd_left + 1
print((b - a + 1) - (cv + dv - cdv))
import fractions
a, b, c, d = map(int, input().split())
print((b-a+1)-(((b//c)+(b//d))-(((a-1)//c)+((a-1)//d))-(b//(c*d//fractions.gcd(c,d))+((a-1)//(c*d//fractions.gcd(c,d))))))
import fractions

a,b,c,d= map(int,input().split())
x = (b//c)-(a//c)
y = (b//d)-(a//d)
lcm = (c*d)//fractions.gcd(c,d)
z = (b//lcm)-(a//lcm)

print(b-a-x-y+z+1)
from fractions import gcd

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

def solve(n, lcm):
  res = n - n // c - n // d + n // lcm
  return res

print(int(solve(b, lcm) - solve(a-1, lcm)))
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    a,b,c,d = IL()
    length = b-a
    mc = length//c
    md = length//d
    lcm = c*d//math.gcd(c,d)
    mcd = length//lcm
    print(length-mc-md+mcd)
    exit()