from math import gcd

from decimal import Decimal as dec 

a, b, c, d = list(map(dec,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(int(c), int(d))

e = dec(e)

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(g)
from math import gcd as gcd

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

#cでわれるもの

s = gcd(c, d)

p = c * d // s

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)))
from math import gcd
from decimal import Decimal as dec

a, b, c, d = list(map(dec, 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(int(c), int(d))
e = dec(e)
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(g)

from math import gcd as gcd

a, b, c, d = list(map(int, input().split()))
# cでわれるもの
s = gcd(c, d)
p = c * d // s
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)))

-from math import gcd -from decimal import Decimal as dec +from math import gcd as gcd -a, b, c, d = list(map(dec, 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(int(c), int(d)) -e = dec(e) -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(g) +a, b, c, d = list(map(int, input().split())) +# cでわれるもの +s = gcd(c, d) +p = c * d // s +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)))