from fractions import gcd

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



# cye bolunenler

c_numbers = b//c - (a-1)//c

# dye bolunenler

d_numbers = b//d - (a-1)//d

# ortak bolunenler

gcd_number = c*d // gcd(c, d)

ortak = b//(gcd_number) - (a-1)//(gcd_number)

# result

print((b-a+1-(c_numbers+d_numbers-ortak)))
from fractions import gcd

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



# cye bolunenler

c_numbers = b//c - (a-1)//c

# dye bolunenler

d_numbers = b//d - (a-1)//d

# ortak bolunenler

gcd_number = c*d // gcd(c, d)

ortak = b//gcd_number - (a-1)//gcd_number

# result

print((b-a+1-(c_numbers+d_numbers-ortak)))
from fractions import gcd

a, b, c, d = list(map(int, input().split(" ")))
# cye bolunenler
c_numbers = b // c - (a - 1) // c
# dye bolunenler
d_numbers = b // d - (a - 1) // d
# ortak bolunenler
gcd_number = c * d // gcd(c, d)
ortak = b // (gcd_number) - (a - 1) // (gcd_number)
# result
print((b - a + 1 - (c_numbers + d_numbers - ortak)))

from fractions import gcd

a, b, c, d = list(map(int, input().split(" ")))
# cye bolunenler
c_numbers = b // c - (a - 1) // c
# dye bolunenler
d_numbers = b // d - (a - 1) // d
# ortak bolunenler
gcd_number = c * d // gcd(c, d)
ortak = b // gcd_number - (a - 1) // gcd_number
# result
print((b - a + 1 - (c_numbers + d_numbers - ortak)))

-ortak = b // (gcd_number) - (a - 1) // (gcd_number) +ortak = b // gcd_number - (a - 1) // gcd_number