# n, k = map(int, input().split())

# h = []

# for i in range(n):

#     h.append(int(input()))



# h.sort(reverse=True)

# ans = []

# for i in range(k):

#     if i+k-1 >= n:

#         break

#     ans.append(h[i] - h[i+k-1])

# print(min(ans))



from fractions import gcd

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



def lcm(a):

    LCM = a[0]

    n = len(a)

    for i in range(1, n):

        LCM = LCM * a[i] // gcd(LCM, a[i])

    return LCM



lcm = lcm([c,d])



# a~bまでのうち、cの倍数

modC = b//c - (a-1)//c



# a~bまでのうち、dの倍数

modD = b//d - (a-1)//d



modCD = b//(lcm) - (a-1)//(lcm)



ans = b - a + 1 - modC - modD + modCD

# print(modC)

# print(modD)

# print(modCD)

print(ans)
import math

def lcm(a):

    LCM = a[0]

    for i in range(1, len(a)):

        LCM = LCM * a[i] // math.gcd(LCM, a[i])

    return LCM



def f(k):

    return b//k - (a-1)//k



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

ALL = b - a + 1

ans = ALL - (f(c) + f(d) - f(lcm([c,d])))

print(ans)
# n, k = map(int, input().split())
# h = []
# for i in range(n):
#     h.append(int(input()))
# h.sort(reverse=True)
# ans = []
# for i in range(k):
#     if i+k-1 >= n:
#         break
#     ans.append(h[i] - h[i+k-1])
# print(min(ans))
from fractions import gcd

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


def lcm(a):
    LCM = a[0]
    n = len(a)
    for i in range(1, n):
        LCM = LCM * a[i] // gcd(LCM, a[i])
    return LCM


lcm = lcm([c, d])
# a~bまでのうち、cの倍数
modC = b // c - (a - 1) // c
# a~bまでのうち、dの倍数
modD = b // d - (a - 1) // d
modCD = b // (lcm) - (a - 1) // (lcm)
ans = b - a + 1 - modC - modD + modCD
# print(modC)
# print(modD)
# print(modCD)
print(ans)

import math


def lcm(a):
    LCM = a[0]
    for i in range(1, len(a)):
        LCM = LCM * a[i] // math.gcd(LCM, a[i])
    return LCM


def f(k):
    return b // k - (a - 1) // k


a, b, c, d = list(map(int, input().split()))
ALL = b - a + 1
ans = ALL - (f(c) + f(d) - f(lcm([c, d])))
print(ans)

-# n, k = map(int, input().split()) -# h = [] -# for i in range(n): -#     h.append(int(input())) -# h.sort(reverse=True) -# ans = [] -# for i in range(k): -#     if i+k-1 >= n: -#         break -#     ans.append(h[i] - h[i+k-1]) -# print(min(ans)) -from fractions import gcd - -a, b, c, d = list(map(int, input().split())) +import math -    n = len(a) -    for i in range(1, n): -        LCM = LCM * a[i] // gcd(LCM, a[i]) +    for i in range(1, len(a)): +        LCM = LCM * a[i] // math.gcd(LCM, a[i]) -lcm = lcm([c, d]) -# a~bまでのうち、cの倍数 -modC = b // c - (a - 1) // c -# a~bまでのうち、dの倍数 -modD = b // d - (a - 1) // d -modCD = b // (lcm) - (a - 1) // (lcm) -ans = b - a + 1 - modC - modD + modCD -# print(modC) -# print(modD) -# print(modCD) +def f(k): +    return b // k - (a - 1) // k + + +a, b, c, d = list(map(int, input().split())) +ALL = b - a + 1 +ans = ALL - (f(c) + f(d) - f(lcm([c, d])))