from fractions import gcd



def lcm(x, y):

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



A, B, C, D = list(map(int, input().split()))



c = B // C - (A - 1) // C

d = B // D - (A - 1) // D

CD = lcm(C, D)

cd = B // CD - (A - 1) // CD



ans = (B - A + 1) - (c + d - cd)

print(ans)
import sys



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





def gcd(a, b):

    while b != 0:

        a, b = b, a % b

    return a





def lcm(a, b):

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





def resolve():

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



    l = lcm(c, d)



    def calc(n):

        res = n // c + n // d - n // l

        return n - res



    print((calc(b) - calc(a - 1)))





if __name__ == '__main__':

    resolve()

from fractions import gcd


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


A, B, C, D = list(map(int, input().split()))
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
CD = lcm(C, D)
cd = B // CD - (A - 1) // CD
ans = (B - A + 1) - (c + d - cd)
print(ans)

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


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


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


def resolve():
    a, b, c, d = list(map(int, input().split()))
    l = lcm(c, d)

    def calc(n):
        res = n // c + n // d - n // l
        return n - res

    print((calc(b) - calc(a - 1)))


if __name__ == "__main__":
    resolve()

-from fractions import gcd +import sys + +sys.setrecursionlimit(10**7) +f_inf = float("inf") +mod = 10**9 + 7 -def lcm(x, y): -    return (x * y) // gcd(x, y) +def gcd(a, b): +    while b != 0: +        a, b = b, a % b +    return a -A, B, C, D = list(map(int, input().split())) -c = B // C - (A - 1) // C -d = B // D - (A - 1) // D -CD = lcm(C, D) -cd = B // CD - (A - 1) // CD -ans = (B - A + 1) - (c + d - cd) -print(ans) +def lcm(a, b): +    return a * b // gcd(a, b) + + +def resolve(): +    a, b, c, d = list(map(int, input().split())) +    l = lcm(c, d) + +    def calc(n): +        res = n // c + n // d - n // l +        return n - res + +    print((calc(b) - calc(a - 1))) + + +if __name__ == "__main__": +    resolve()