import fractions

A, B, C, D = [int(i) for i in input().split()]

result = B+1 - A

def lcm(a, b):

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

def wareru(min_num, max_num, waru):

    return (max_num)//waru - (min_num-1)//waru

result -= wareru(A, B, C) + wareru(A, B, D) - wareru(A, B, lcm(C,D))

print(result)
from fractions import gcd

A, B, C, D = [int(i) for i in input().split()]

result = B+1 - A

def lcm(a, b):

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

def wareru(min_num, max_num, waru):

    return (max_num)//waru - (min_num-1)//waru

result -= wareru(A, B, C) + wareru(A, B, D) - wareru(A, B, lcm(C,D))

print(result)
import fractions

A, B, C, D = [int(i) for i in input().split()]
result = B + 1 - A


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


def wareru(min_num, max_num, waru):
    return (max_num) // waru - (min_num - 1) // waru


result -= wareru(A, B, C) + wareru(A, B, D) - wareru(A, B, lcm(C, D))
print(result)

from fractions import gcd

A, B, C, D = [int(i) for i in input().split()]
result = B + 1 - A


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


def wareru(min_num, max_num, waru):
    return (max_num) // waru - (min_num - 1) // waru


result -= wareru(A, B, C) + wareru(A, B, D) - wareru(A, B, lcm(C, D))
print(result)

-import fractions +from fractions import gcd -    return (a * b) // fractions.gcd(a, b) +    return (a * b) // gcd(a, b)