from fractions import gcd



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

l = C * D // gcd(C, D)

x = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // l

y = B - B // C - B // D + B // l

print((y - x))
def gcd(a,b):

  while b:

    a, b = b, a%b

  return a



def lcm(a,b):

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



def g(X):

  return X - X//C - X//D + X//lcm(C,D)



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



ans = g(B) - g(A-1)

print(ans)
from fractions import gcd

A, B, C, D = list(map(int, input().split()))
l = C * D // gcd(C, D)
x = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // l
y = B - B // C - B // D + B // l
print((y - x))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def g(X):
    return X - X // C - X // D + X // lcm(C, D)


A, B, C, D = list(map(int, input().split()))
ans = g(B) - g(A - 1)
print(ans)

-from fractions import gcd +def gcd(a, b): +    while b: +        a, b = b, a % b +    return a + + +def lcm(a, b): +    return a * b // gcd(a, b) + + +def g(X): +    return X - X // C - X // D + X // lcm(C, D) + -l = C * D // gcd(C, D) -x = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // l -y = B - B // C - B // D + B // l -print((y - x)) +ans = g(B) - g(A - 1) +print(ans)