def gcd(x, y):

    if y == 0:

        return x

    return gcd(y, x % y)





def lcm(x, y):

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





def cnt(u, x, y):

    return u - (u // x + u // y - u // lcm(x, y))





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



ans = 0



# B以下

ans += cnt(B, C, D)



# A-1以下

ans -= cnt(A - 1, C, D)



print(ans)

def gcd(a, b):

    if b == 0: return a

    return gcd(b, a % b)





def lcm(a, b):

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





def calc(x, a, b):

    return x - x // a - x // b + x // lcm(a, b)





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

print((calc(b, c, d) - calc(a - 1, c, d)))

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


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


def cnt(u, x, y):
    return u - (u // x + u // y - u // lcm(x, y))


A, B, C, D = list(map(int, input().split()))
ans = 0
# B以下
ans += cnt(B, C, D)
# A-1以下
ans -= cnt(A - 1, C, D)
print(ans)

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


def calc(x, a, b):
    return x - x // a - x // b + x // lcm(a, b)


a, b, c, d = list(map(int, input().split()))
print((calc(b, c, d) - calc(a - 1, c, d)))

-def gcd(x, y): -    if y == 0: -        return x -    return gcd(y, x % y) +def gcd(a, b): +    if b == 0: +        return a +    return gcd(b, a % b) -def lcm(x, y): -    return x // gcd(x, y) * y +def lcm(a, b): +    return a // gcd(a, b) * b -def cnt(u, x, y): -    return u - (u // x + u // y - u // lcm(x, y)) +def calc(x, a, b): +    return x - x // a - x // b + x // lcm(a, b) -A, B, C, D = list(map(int, input().split())) -ans = 0 -# B以下 -ans += cnt(B, C, D) -# A-1以下 -ans -= cnt(A - 1, C, D) -print(ans) +a, b, c, d = list(map(int, input().split())) +print((calc(b, c, d) - calc(a - 1, c, d)))