import fractions

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

p = b//c + (-a//c) +1

q = b//d + (-a//d) +1

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

print((b-a+1-p-q+r))
def gcd(x,y):

  if y == 0:

    return x

  else:

    return gcd(y,x%y)

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

p = b//c + (-a//c) +1

q = b//d + (-a//d) +1

r = b*gcd(c,d)//(c*d) + (-a*gcd(c,d)//(c*d)) +1

print((b-a+1-p-q+r))
import fractions

a, b, c, d = list(map(int, input().split()))
p = b // c + (-a // c) + 1
q = b // d + (-a // d) + 1
r = b * fractions.gcd(c, d) // (c * d) + (-a * fractions.gcd(c, d) // (c * d)) + 1
print((b - a + 1 - p - q + r))

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


a, b, c, d = list(map(int, input().split()))
p = b // c + (-a // c) + 1
q = b // d + (-a // d) + 1
r = b * gcd(c, d) // (c * d) + (-a * gcd(c, d) // (c * d)) + 1
print((b - a + 1 - p - q + r))

-import fractions +def gcd(x, y): +    if y == 0: +        return x +    else: +        return gcd(y, x % y) + -r = b * fractions.gcd(c, d) // (c * d) + (-a * fractions.gcd(c, d) // (c * d)) + 1 +r = b * gcd(c, d) // (c * d) + (-a * gcd(c, d) // (c * d)) + 1