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

x = C

y = D

while y>0:

    x,y = y,x%y

E = (C//x)*D

bc = B//C

bd = B//D

be = B//E

b = B-(bc+bd-be)

ac = (A-1)//C

ad = (A-1)//D

ae = (A-1)//E

a = A-1-(ac+ad-ae)

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

    while y>0:

        x,y = y,x%y

    return x

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

c1 = B//C-(A-1)//C

d1 = B//D-(A-1)//D

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

e1 = B//E-(A-1)//E

print((B-A+1-c1-d1+e1))
A, B, C, D = list(map(int, input().split()))
x = C
y = D
while y > 0:
    x, y = y, x % y
E = (C // x) * D
bc = B // C
bd = B // D
be = B // E
b = B - (bc + bd - be)
ac = (A - 1) // C
ad = (A - 1) // D
ae = (A - 1) // E
a = A - 1 - (ac + ad - ae)
print((b - a))

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


A, B, C, D = list(map(int, input().split()))
c1 = B // C - (A - 1) // C
d1 = B // D - (A - 1) // D
E = (C // gcd(C, D)) * D
e1 = B // E - (A - 1) // E
print((B - A + 1 - c1 - d1 + e1))

+def gcd(x, y): +    while y > 0: +        x, y = y, x % y +    return x + + -x = C -y = D -while y > 0: -    x, y = y, x % y -E = (C // x) * D -bc = B // C -bd = B // D -be = B // E -b = B - (bc + bd - be) -ac = (A - 1) // C -ad = (A - 1) // D -ae = (A - 1) // E -a = A - 1 - (ac + ad - ae) -print((b - a)) +c1 = B // C - (A - 1) // C +d1 = B // D - (A - 1) // D +E = (C // gcd(C, D)) * D +e1 = B // E - (A - 1) // E +print((B - A + 1 - c1 - d1 + e1))