from fractions import gcd

def lcm(a,b):

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

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

a-=1

print(((b-a)-(b//c+b//d-a//c-a//d-(b//lcm(c,d))+(a//lcm(c,d)))))

import sys

import bisect



sys.setrecursionlimit(1 << 25)

read = sys.stdin.readline

def gcd(a,b):

    r = a%b;

    while r > 0:

        a = b

        b = r

        r = a%b

    return b

def lcm(a,b):

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

def main():

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

    acnum = (a-1)//c

    bcnum = (b)//c

    adnum = (a-1)//d

    bdnum = (b)//d

    acdnum = (a-1)//(lcm(c,d))

    bcdnum = (b)//(lcm(c,d))



    print(((b-a+1)-(bcnum-acnum)-(bdnum-adnum) + (bcdnum-acdnum)))

if __name__ == '__main__':

    main()

from fractions import gcd


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


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

import sys
import bisect

sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


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


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


def main():
    a, b, c, d = list(map(int, read().split()))
    acnum = (a - 1) // c
    bcnum = (b) // c
    adnum = (a - 1) // d
    bdnum = (b) // d
    acdnum = (a - 1) // (lcm(c, d))
    bcdnum = (b) // (lcm(c, d))
    print(((b - a + 1) - (bcnum - acnum) - (bdnum - adnum) + (bcdnum - acdnum)))


if __name__ == "__main__":
    main()

-from fractions import gcd +import sys +import bisect + +sys.setrecursionlimit(1 << 25) +read = sys.stdin.readline + + +def gcd(a, b): +    r = a % b +    while r > 0: +        a = b +        b = r +        r = a % b +    return b -a, b, c, d = list(map(int, input().split())) -a -= 1 -print( -    ( -        (b - a) -        - (b // c + b // d - a // c - a // d - (b // lcm(c, d)) + (a // lcm(c, d))) -    ) -) +def main(): +    a, b, c, d = list(map(int, read().split())) +    acnum = (a - 1) // c +    bcnum = (b) // c +    adnum = (a - 1) // d +    bdnum = (b) // d +    acdnum = (a - 1) // (lcm(c, d)) +    bcdnum = (b) // (lcm(c, d)) +    print(((b - a + 1) - (bcnum - acnum) - (bdnum - adnum) + (bcdnum - acdnum))) + + +if __name__ == "__main__": +    main()