from fractions import gcd 



l = list(map(int,input().split()))

A = l[0]

B = l[1]

C = l[2]

D = l[3]



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



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

f = f+(B//D - (A-1)//D)

ans = B-A+1-f + B//E-(A-1)//E

print(ans)

def gcd(m,n):

    i = max(m,n)

    j = min(m,n)

    return sgcd(i,j)



def sgcd(i,j):

    if j == 0:

        return i

    else:

        return sgcd(j,i%j)



l = list(map(int,input().split()))

A = l[0]

B = l[1]

C = l[2]

D = l[3]



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



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

f = f+(B//D - (A-1)//D)

ans = B-A+1-f + B//E-(A-1)//E

print(ans)

from fractions import gcd

l = list(map(int, input().split()))
A = l[0]
B = l[1]
C = l[2]
D = l[3]
E = C * D // gcd(C, D)
f = B // C - (A - 1) // C
f = f + (B // D - (A - 1) // D)
ans = B - A + 1 - f + B // E - (A - 1) // E
print(ans)

def gcd(m, n):
    i = max(m, n)
    j = min(m, n)
    return sgcd(i, j)


def sgcd(i, j):
    if j == 0:
        return i
    else:
        return sgcd(j, i % j)


l = list(map(int, input().split()))
A = l[0]
B = l[1]
C = l[2]
D = l[3]
E = C * D // gcd(C, D)
f = B // C - (A - 1) // C
f = f + (B // D - (A - 1) // D)
ans = B - A + 1 - f + B // E - (A - 1) // E
print(ans)

-from fractions import gcd +def gcd(m, n): +    i = max(m, n) +    j = min(m, n) +    return sgcd(i, j) + + +def sgcd(i, j): +    if j == 0: +        return i +    else: +        return sgcd(j, i % j) +