def gcd(a, b):

    while b:

        a, b = b, a % b

    return a



def lcm(a, b):

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



temp=input().split()

A=int(temp[0])

B=int(temp[1])

C=int(temp[2])

D=int(temp[3])



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

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

s=lcm(C, D)

z=B//s-(A-1)//s



print((int(B-A+1-x-y+z)))
import fractions



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

x=C*D//fractions.gcd(C, D)

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

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

r=B//x-(A-1)//x

print((int(B-(A-1)-(p+q-r))))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


temp = input().split()
A = int(temp[0])
B = int(temp[1])
C = int(temp[2])
D = int(temp[3])
x = B // C - (A - 1) // C
y = B // D - (A - 1) // D
s = lcm(C, D)
z = B // s - (A - 1) // s
print((int(B - A + 1 - x - y + z)))

import fractions

A, B, C, D = list(map(int, input().split()))
x = C * D // fractions.gcd(C, D)
p = B // C - (A - 1) // C
q = B // D - (A - 1) // D
r = B // x - (A - 1) // x
print((int(B - (A - 1) - (p + q - r))))

-def gcd(a, b): -    while b: -        a, b = b, a % b -    return a +import fractions - -def lcm(a, b): -    return a * b // gcd(a, b) - - -temp = input().split() -A = int(temp[0]) -B = int(temp[1]) -C = int(temp[2]) -D = int(temp[3]) -x = B // C - (A - 1) // C -y = B // D - (A - 1) // D -s = lcm(C, D) -z = B // s - (A - 1) // s -print((int(B - A + 1 - x - y + z))) +A, B, C, D = list(map(int, input().split())) +x = C * D // fractions.gcd(C, D) +p = B // C - (A - 1) // C +q = B // D - (A - 1) // D +r = B // x - (A - 1) // x +print((int(B - (A - 1) - (p + q - r))))