import fractions

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

cdlcm= c*d//fractions.gcd(c,d)

a-=1

tc = b//c-a//c

td = b//d-a//d

tlcm = b//cdlcm-a//cdlcm

print((b-a-tc-td+tlcm))
# gcd: 最大公約数

def gcd(x,y):

  while y:

    x, y = y, x%y

  return x

# lcm: 最小公約数

def lcm(x,y):

  return x*y//gcd(x,y)

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

a-=1

e=lcm(c,d)

tc=b//c-a//c

td=b//d-a//d

te=b//e-a//e

print((b-a-tc-td+te))
import fractions

a, b, c, d = list(map(int, input().split()))
cdlcm = c * d // fractions.gcd(c, d)
a -= 1
tc = b // c - a // c
td = b // d - a // d
tlcm = b // cdlcm - a // cdlcm
print((b - a - tc - td + tlcm))

# gcd: 最大公約数
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


# lcm: 最小公約数
def lcm(x, y):
    return x * y // gcd(x, y)


a, b, c, d = list(map(int, input().split()))
a -= 1
e = lcm(c, d)
tc = b // c - a // c
td = b // d - a // d
te = b // e - a // e
print((b - a - tc - td + te))

-import fractions +# gcd: 最大公約数 +def gcd(x, y): +    while y: +        x, y = y, x % y +    return x + + +# lcm: 最小公約数 +def lcm(x, y): +    return x * y // gcd(x, y) + -cdlcm = c * d // fractions.gcd(c, d) +e = lcm(c, d) -tlcm = b // cdlcm - a // cdlcm -print((b - a - tc - td + tlcm)) +te = b // e - a // e +print((b - a - tc - td + te))