from fractions import gcd

a, b, c, d = list(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)))
from fractions import gcd

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



def lcm(x,y):

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

e = lcm(c,d)



f = (b//c + b//d) - b//e

g = ((a-1)//c + (a-1)//d) - (a-1)//e

print((b-a+1-(f-g)))
from fractions import gcd

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

from fractions import gcd

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


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


e = lcm(c, d)
f = (b // c + b // d) - b // e
g = ((a - 1) // c + (a - 1) // d) - (a - 1) // e
print((b - a + 1 - (f - g)))

-e = b // c - (a - 1) // c -f = b // d - (a - 1) // d -g = lcm(c, d) -h = b // g - (a - 1) // g -print((b - a + 1 - (e + f - h))) +e = lcm(c, d) +f = (b // c + b // d) - b // e +g = ((a - 1) // c + (a - 1) // d) - (a - 1) // e +print((b - a + 1 - (f - g)))