from fractions import gcd





def lcm(x, y):

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





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

SUM = B - A + 1

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

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

cd = (B // lcm(C, D) - (A - 1) // lcm(C, D))

print((B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - cd)))

from fractions import gcd





def lcm(x, y):

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





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

SUM = B - A + 1

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

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

cd = (B // lcm(C, D) - (A - 1) // lcm(C, D))

print((B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - (B // lcm(C, D) - (A - 1) // lcm(C, D)))))

from fractions import gcd


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


A, B, C, D = list(map(int, input().split()))
SUM = B - A + 1
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
cd = B // lcm(C, D) - (A - 1) // lcm(C, D)
print((B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - cd)))

from fractions import gcd


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


A, B, C, D = list(map(int, input().split()))
SUM = B - A + 1
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
cd = B // lcm(C, D) - (A - 1) // lcm(C, D)
print(
    (
        B
        - A
        + 1
        - (
            B // C
            - (A - 1) // C
            + B // D
            - (A - 1) // D
            - (B // lcm(C, D) - (A - 1) // lcm(C, D))
        )
    )
)

-print((B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - cd))) +print( +    ( +        B +        - A +        + 1 +        - ( +            B // C +            - (A - 1) // C +            + B // D +            - (A - 1) // D +            - (B // lcm(C, D) - (A - 1) // lcm(C, D)) +        ) +    ) +)