import fractions

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

 

def wareruzu(x):

    if b < x:

        return 0

    if b == x:

        return 1

    start_a = a if a % x == 0 else a - (a % x) + x

    end_b = b - (b % x) # bより小さい最大の値。

    m = end_b - start_a

    if m < 0:

        return 0

    return int(m // x) + 1

 

all_n = b - a + 1

print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c*d) // fractions.gcd(c,d))))
import fractions

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

 

def wareruzu(x):

    if b < x:

        return 0

    if b == x:

        return 1

    start_a = a if a % x == 0 else a - (a % x) + x

    end_b = b - (b % x) # bより小さい最大の値。

    m = end_b - start_a

    return m // x + 1

 

all_n = b - a + 1

print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c*d) // fractions.gcd(c,d))))
import fractions

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


def wareruzu(x):
    if b < x:
        return 0
    if b == x:
        return 1
    start_a = a if a % x == 0 else a - (a % x) + x
    end_b = b - (b % x)  # bより小さい最大の値。
    m = end_b - start_a
    if m < 0:
        return 0
    return int(m // x) + 1


all_n = b - a + 1
print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c * d) // fractions.gcd(c, d))))

import fractions

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


def wareruzu(x):
    if b < x:
        return 0
    if b == x:
        return 1
    start_a = a if a % x == 0 else a - (a % x) + x
    end_b = b - (b % x)  # bより小さい最大の値。
    m = end_b - start_a
    return m // x + 1


all_n = b - a + 1
print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c * d) // fractions.gcd(c, d))))

-    if m < 0: -        return 0 -    return int(m // x) + 1 +    return m // x + 1