def gcd(x,y):

    while y>0:

        x,y = y,x%y

    return x

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

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

c1 = B//C

d1 = B//D

e1 = B//E

y = B-(c1+d1-e1)

c2 = (A-1)//C

d2 = (A-1)//D

e2 = (A-1)//E

x = (A-1)-(c2+d2-e2)

print((y-x))
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()))
E = (C // gcd(C, D)) * D
c1 = B // C
d1 = B // D
e1 = B // E
y = B - (c1 + d1 - e1)
c2 = (A - 1) // C
d2 = (A - 1) // D
e2 = (A - 1) // E
x = (A - 1) - (c2 + d2 - e2)
print((y - x))

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 - - -E = (C // gcd(C, D)) * D -c1 = B // C -d1 = B // D -e1 = B // E -y = B - (c1 + d1 - e1) -c2 = (A - 1) // C -d2 = (A - 1) // D -e2 = (A - 1) // E -x = (A - 1) - (c2 + d2 - e2) -print((y - 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))