import fractions



def euclid(x, y):

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



def dif(x, C, D):

    return x - (x//C) - (x//D) + (x//(euclid(C, D)))



def main():

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

    return dif(B, C, D) - dif((A-1), C, D)



if __name__ == '__main__':

    print((main()))
# 最小公倍数を返す

def euclid(x, y):

    x_1 = x

    y_1 = y

    a = x_1%y_1

    while a != 0:

        x_1 = y_1

        y_1 = a

        a = x_1%y_1

    return (x * y) // y_1



# x以下のCとDで割り切れる数を返す

def dif(x, C, D):

    return x - (x//C) - (x//D) + (x//(euclid(C, D)))



def main():

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

    return dif(B, C, D) - dif((A-1), C, D)



if __name__ == '__main__':

    print((int(main())))
import fractions


def euclid(x, y):
    return (x * y) // fractions.gcd(x, y)


def dif(x, C, D):
    return x - (x // C) - (x // D) + (x // (euclid(C, D)))


def main():
    A, B, C, D = list(map(int, input().split()))
    return dif(B, C, D) - dif((A - 1), C, D)


if __name__ == "__main__":
    print((main()))

# 最小公倍数を返す
def euclid(x, y):
    x_1 = x
    y_1 = y
    a = x_1 % y_1
    while a != 0:
        x_1 = y_1
        y_1 = a
        a = x_1 % y_1
    return (x * y) // y_1


# x以下のCとDで割り切れる数を返す
def dif(x, C, D):
    return x - (x // C) - (x // D) + (x // (euclid(C, D)))


def main():
    A, B, C, D = list(map(int, input().split()))
    return dif(B, C, D) - dif((A - 1), C, D)


if __name__ == "__main__":
    print((int(main())))

-import fractions +# 最小公倍数を返す +def euclid(x, y): +    x_1 = x +    y_1 = y +    a = x_1 % y_1 +    while a != 0: +        x_1 = y_1 +        y_1 = a +        a = x_1 % y_1 +    return (x * y) // y_1 -def euclid(x, y): -    return (x * y) // fractions.gcd(x, y) - - +# x以下のCとDで割り切れる数を返す -    print((main())) +    print((int(main())))