import fractions



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

g=int(fractions.gcd(c,d))

l=int((c*d)/g)



print((b-a+1-int(b//c)+int((a-1)//c)-int(b//d)+int((a-1)//d)+int(b//l)-int((a-1)//l)))

import fractions



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

g=(fractions.gcd(c,d))

l=int((c*d)/g)



print((b-a+1-int(b//c)+int((a-1)//c)-int(b//d)+int((a-1)//d)+int(b//l)-int((a-1)//l)))

import fractions

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

import fractions

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

-g = int(fractions.gcd(c, d)) +g = fractions.gcd(c, d)