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



def gcd(x, y):

    while y > 0:

        x, y = y, x % y

    return x



def lcm(x, y):

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



c = (A - 1) // C

d = (A - 1) // D

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



tmp1 = c + d - cd



c = B // C

d = B // D

cd = B // lcm(C, D)



tmp2 = c + d -cd



print(((B - A + 1) - (tmp2 - tmp1)))
import math



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

lcm = (c * d) // math.gcd(c, d)



a -= 1



x = a // c

y = a // d

z = a // lcm



ans1 = a - (x + y - z)



x = b // c

y = b // d

z = b // lcm



ans2 = b - (x + y - z)



print((ans2 - ans1))
A, B, C, D = list(map(int, input().split()))


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


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


c = (A - 1) // C
d = (A - 1) // D
cd = (A - 1) // lcm(C, D)
tmp1 = c + d - cd
c = B // C
d = B // D
cd = B // lcm(C, D)
tmp2 = c + d - cd
print(((B - A + 1) - (tmp2 - tmp1)))

import math

a, b, c, d = list(map(int, input().split()))
lcm = (c * d) // math.gcd(c, d)
a -= 1
x = a // c
y = a // d
z = a // lcm
ans1 = a - (x + y - z)
x = b // c
y = b // d
z = b // lcm
ans2 = b - (x + y - z)
print((ans2 - ans1))

-A, B, C, D = list(map(int, input().split())) +import math - -def gcd(x, y): -    while y > 0: -        x, y = y, x % y -    return x - - -def lcm(x, y): -    return (x * y) // gcd(x, y) - - -c = (A - 1) // C -d = (A - 1) // D -cd = (A - 1) // lcm(C, D) -tmp1 = c + d - cd -c = B // C -d = B // D -cd = B // lcm(C, D) -tmp2 = c + d - cd -print(((B - A + 1) - (tmp2 - tmp1))) +a, b, c, d = list(map(int, input().split())) +lcm = (c * d) // math.gcd(c, d) +a -= 1 +x = a // c +y = a // d +z = a // lcm +ans1 = a - (x + y - z) +x = b // c +y = b // d +z = b // lcm +ans2 = b - (x + y - z) +print((ans2 - ans1))