def gcd(a, b):

    if b == 0:

        return a

    else:

        return gcd(b, a%b)



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



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



count1 = (B // C - A // C)

count2 = (B // D - A // D)

count3 = (B // CD - A // CD)



if A % C == 0:

    count1 += 1



if A % D == 0:

    count2 += 1



if A % CD == 0:

    count3 += 1 



print((B - A + 1 - ((count1 + count2) - count3)))

def gcd(a, b):

    if b == 0:

        return a

    else:

        return gcd(b, a%b)



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



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



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

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

count3 = (B // CD - (A - 1) // CD)



print((B - (A - 1) - ((count1 + count2) - count3)))
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


A, B, C, D = list(map(int, input().split()))
CD = C * D // gcd(C, D)
count1 = B // C - A // C
count2 = B // D - A // D
count3 = B // CD - A // CD
if A % C == 0:
    count1 += 1
if A % D == 0:
    count2 += 1
if A % CD == 0:
    count3 += 1
print((B - A + 1 - ((count1 + count2) - count3)))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


A, B, C, D = list(map(int, input().split()))
CD = C * D // gcd(C, D)
count1 = B // C - (A - 1) // C
count2 = B // D - (A - 1) // D
count3 = B // CD - (A - 1) // CD
print((B - (A - 1) - ((count1 + count2) - count3)))

-count1 = B // C - A // C -count2 = B // D - A // D -count3 = B // CD - A // CD -if A % C == 0: -    count1 += 1 -if A % D == 0: -    count2 += 1 -if A % CD == 0: -    count3 += 1 -print((B - A + 1 - ((count1 + count2) - count3))) +count1 = B // C - (A - 1) // C +count2 = B // D - (A - 1) // D +count3 = B // CD - (A - 1) // CD +print((B - (A - 1) - ((count1 + count2) - count3)))