import fractions



def lcm(x,y):

    return (x*y)//fractions.gcd(x,y)



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

d1=b//c

d2=b//d

d3=b//lcm(c,d)



d4=(a-1)//c

d5=(a-1)//d

d6=(a-1)//lcm(c,d)



ansb=b-(d1+d2-d3)

ansa=a-1-(d4+d5-d6)

print((ansb-ansa))

def gcd(x,y):

    if x < y:

        x,y = y,x

        

    if y == 0:

        return x

    else:

        return gcd(y,x%y)



def lcm(x,y):

    return (x*y)//gcd(x,y)



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



al = b-a+1



cnt_c = b//c - (a-1)//c 



cnt_d = b//d - (a-1)//d 



cnt_t = b//lcm(c,d) - (a-1)//lcm(c,d) 



print((al - cnt_c - cnt_d + cnt_t))
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


a, b, c, d = list(map(int, input().split()))
d1 = b // c
d2 = b // d
d3 = b // lcm(c, d)
d4 = (a - 1) // c
d5 = (a - 1) // d
d6 = (a - 1) // lcm(c, d)
ansb = b - (d1 + d2 - d3)
ansa = a - 1 - (d4 + d5 - d6)
print((ansb - ansa))

def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def lcm(x, y):
    return (x * y) // gcd(x, y)


a, b, c, d = list(map(int, input().split()))
al = b - a + 1
cnt_c = b // c - (a - 1) // c
cnt_d = b // d - (a - 1) // d
cnt_t = b // lcm(c, d) - (a - 1) // lcm(c, d)
print((al - cnt_c - cnt_d + cnt_t))

-import fractions +def gcd(x, y): +    if x < y: +        x, y = y, x +    if y == 0: +        return x +    else: +        return gcd(y, x % y) -    return (x * y) // fractions.gcd(x, y) +    return (x * y) // gcd(x, y) -d1 = b // c -d2 = b // d -d3 = b // lcm(c, d) -d4 = (a - 1) // c -d5 = (a - 1) // d -d6 = (a - 1) // lcm(c, d) -ansb = b - (d1 + d2 - d3) -ansa = a - 1 - (d4 + d5 - d6) -print((ansb - ansa)) +al = b - a + 1 +cnt_c = b // c - (a - 1) // c +cnt_d = b // d - (a - 1) // d +cnt_t = b // lcm(c, d) - (a - 1) // lcm(c, d) +print((al - cnt_c - cnt_d + cnt_t))