def main():

    a, b, c, d = (int(i) for i in input().split())



    def gcd(x, y):

        if y == 0:

            return x

        while y != 0:

            x, y = y, x % y

        return x



    def lcm(x, y):

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



    def f(x):

        p = x//c

        q = x//d

        r = x//lcm(c, d)

        return x - p - q + r



    print((f(b) - f(a-1)))





if __name__ == '__main__':

    main()

def main():

    from math import gcd

    a, b, c, d = (int(i) for i in input().split())

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

    ans = b - (b//c + b//d - b//L)

    ans -= (a-1) - ((a-1)//c + (a-1)//d - (a-1)//L)

    print(ans)





if __name__ == '__main__':

    main()

def main():
    a, b, c, d = (int(i) for i in input().split())

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

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

    def f(x):
        p = x // c
        q = x // d
        r = x // lcm(c, d)
        return x - p - q + r

    print((f(b) - f(a - 1)))


if __name__ == "__main__":
    main()

def main():
    from math import gcd

    a, b, c, d = (int(i) for i in input().split())
    L = c * d // gcd(c, d)
    ans = b - (b // c + b // d - b // L)
    ans -= (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // L)
    print(ans)


if __name__ == "__main__":
    main()

+    from math import gcd + - -    def gcd(x, y): -        if y == 0: -            return x -        while y != 0: -            x, y = y, x % y -        return x - -    def lcm(x, y): -        return x * y // gcd(x, y) - -    def f(x): -        p = x // c -        q = x // d -        r = x // lcm(c, d) -        return x - p - q + r - -    print((f(b) - f(a - 1))) +    L = c * d // gcd(c, d) +    ans = b - (b // c + b // d - b // L) +    ans -= (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // L) +    print(ans)