# バージョン 3.4.X 以前

import fractions

# バージョン 3.5 以降

# import math





def lcm(x, y):

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





def main():

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

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

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

    tmp = lcm(C, D)

    both = B // tmp - (A - 1) // tmp

    print((B - A + 1 - first - second + both))

    return





main()

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a





def lcm(a, b):

    g = gcd(a, b)



    return a * (b // g)





def main():

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

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

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

    tmp = lcm(C, D)

    both = B // tmp - (A - 1) // tmp

    print((B - A + 1 - c - d + both))

    return





main()

# バージョン 3.4.X 以前
import fractions

# バージョン 3.5 以降
# import math
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def main():
    A, B, C, D = list(map(int, input().split()))
    first = B // C - (A - 1) // C
    second = B // D - (A - 1) // D
    tmp = lcm(C, D)
    both = B // tmp - (A - 1) // tmp
    print((B - A + 1 - first - second + both))
    return


main()

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


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


def main():
    A, B, C, D = list(map(int, input().split()))
    c = B // C - (A - 1) // C
    d = B // D - (A - 1) // D
    tmp = lcm(C, D)
    both = B // tmp - (A - 1) // tmp
    print((B - A + 1 - c - d + both))
    return


main()

-# バージョン 3.4.X 以前 -import fractions +def gcd(a, b): +    while b: +        a, b = b, a % b +    return a -# バージョン 3.5 以降 -# import math -def lcm(x, y): -    return (x * y) // fractions.gcd(x, y) + +def lcm(a, b): +    g = gcd(a, b) +    return a * (b // g) -    first = B // C - (A - 1) // C -    second = B // D - (A - 1) // D +    c = B // C - (A - 1) // C +    d = B // D - (A - 1) // D -    print((B - A + 1 - first - second + both)) +    print((B - A + 1 - c - d + both))