def gcd(a,b):

    while b!=0:

        a,b=b,a%b

    return a



def lcm(a,b):

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



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

a-=1

b_1=b//c

b_1+=b//d

b_1-=b//lcm(c,d)

a_1=a//c

a_1+=a//d

a_1-=a//lcm(c,d)

print(((b-b_1)-(a-a_1)))
a,b,c,d=list(map(int,input().split()))

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a



#a,bの最小公倍数

def lcm(a, b):

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

a1=(a-1)//c

a2=b//c

b1=(a-1)//d

b2=b//d

new_lcm=lcm(c,d)

c1=(a-1)//new_lcm

c2=b//new_lcm

print(((b-a)+1-((a2-a1)+(b2-b1))+(c2-c1)))

#print(a1,a2,b1,b2,c1,c2)

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


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


a, b, c, d = list(map(int, input().split()))
a -= 1
b_1 = b // c
b_1 += b // d
b_1 -= b // lcm(c, d)
a_1 = a // c
a_1 += a // d
a_1 -= a // lcm(c, d)
print(((b - b_1) - (a - a_1)))

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


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


# a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)


a1 = (a - 1) // c
a2 = b // c
b1 = (a - 1) // d
b2 = b // d
new_lcm = lcm(c, d)
c1 = (a - 1) // new_lcm
c2 = b // new_lcm
print(((b - a) + 1 - ((a2 - a1) + (b2 - b1)) + (c2 - c1)))
# print(a1,a2,b1,b2,c1,c2)

+a, b, c, d = list(map(int, input().split())) + + -    while b != 0: +    while b: +# a,bの最小公倍数 -a, b, c, d = list(map(int, input().split())) -a -= 1 -b_1 = b // c -b_1 += b // d -b_1 -= b // lcm(c, d) -a_1 = a // c -a_1 += a // d -a_1 -= a // lcm(c, d) -print(((b - b_1) - (a - a_1))) +a1 = (a - 1) // c +a2 = b // c +b1 = (a - 1) // d +b2 = b // d +new_lcm = lcm(c, d) +c1 = (a - 1) // new_lcm +c2 = b // new_lcm +print(((b - a) + 1 - ((a2 - a1) + (b2 - b1)) + (c2 - c1))) +# print(a1,a2,b1,b2,c1,c2)