def gcd(a, b):

    while b != 0:

        a, b = b, a % b

    return a





def lcm(a, b):

    return a * b // gcd(a, b)





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



s = b - a + 1

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

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

z = b // lcm(c, d) - (a - 1) // lcm(c, d)



print((s - (x + y) + z))

import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)



i_i = lambda: int(i_s())

i_l = lambda: list(map(int, stdin.readline().split()))

i_s = lambda: stdin.readline().rstrip()



def gcd(a,b):

    while b:

        a, b = b, a%b

    return a



def lcm(a,b):

    return a*b//gcd(a,b)



A, B, C, D = i_l()



A -= 1

l = lcm(C,D)



a = (B + C) // C - (A + C) // C

b = (B + D) // D - (A + D) // D

c = (B + l) // l - (A + l) // l



print(((B - A) - a - b + c))
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


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


a, b, c, d = list(map(int, input().split()))
s = b - a + 1
x = b // c - (a - 1) // c
y = b // d - (a - 1) // d
z = b // lcm(c, d) - (a - 1) // lcm(c, d)
print((s - (x + y) + z))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


A, B, C, D = i_l()
A -= 1
l = lcm(C, D)
a = (B + C) // C - (A + C) // C
b = (B + D) // D - (A + D) // D
c = (B + l) // l - (A + l) // l
print(((B - A) - a - b + c))

+import sys + +stdin = sys.stdin +sys.setrecursionlimit(10**7) +i_i = lambda: int(i_s()) +i_l = lambda: list(map(int, stdin.readline().split())) +i_s = lambda: stdin.readline().rstrip() + + -    while b != 0: +    while b: -a, b, c, d = list(map(int, input().split())) -s = b - a + 1 -x = b // c - (a - 1) // c -y = b // d - (a - 1) // d -z = b // lcm(c, d) - (a - 1) // lcm(c, d) -print((s - (x + y) + z)) +A, B, C, D = i_l() +A -= 1 +l = lcm(C, D) +a = (B + C) // C - (A + C) // C +b = (B + D) // D - (A + D) // D +c = (B + l) // l - (A + l) // l +print(((B - A) - a - b + c))