from fractions import gcd





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

LCM = C * D // gcd(C, D)

print((

    B

    - A

    + 1

    - B // C

    + (A - 1) // C

    - B // D

    + (A - 1) // D

    + B // LCM

    - (A - 1) // LCM

))

from math import gcd





def count_indivs(N):

    return N - (N // C + N // D - N // L)





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

L = C * D // gcd(C, D)

print((count_indivs(B) - count_indivs(A - 1)))

from fractions import gcd

A, B, C, D = list(map(int, input().split()))
LCM = C * D // gcd(C, D)
print(
    (
        B
        - A
        + 1
        - B // C
        + (A - 1) // C
        - B // D
        + (A - 1) // D
        + B // LCM
        - (A - 1) // LCM
    )
)

from math import gcd


def count_indivs(N):
    return N - (N // C + N // D - N // L)


A, B, C, D = list(map(int, input().split()))
L = C * D // gcd(C, D)
print((count_indivs(B) - count_indivs(A - 1)))

-from fractions import gcd +from math import gcd + + +def count_indivs(N): +    return N - (N // C + N // D - N // L) + -LCM = C * D // gcd(C, D) -print( -    ( -        B -        - A -        + 1 -        - B // C -        + (A - 1) // C -        - B // D -        + (A - 1) // D -        + B // LCM -        - (A - 1) // LCM -    ) -) +L = C * D // gcd(C, D) +print((count_indivs(B) - count_indivs(A - 1)))