def gcd(i,j):

  if i > j:

    tmp = i

    i = j

    j = tmp

  while i != 0:

    tmp = i

    i = j%i

    j = tmp

  return j

def lcm(i,j):

  return i*j//gcd(i,j)  

def main():

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

  ans = b-a+1

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

  print(ans)





main()

#!/usr/bin/env python3

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

def my_gcd(i,j):

    if i > j: i,j = j,i

    while i != 0:

        if j % i != 0:

            i,j = j%i,i

        else: return i

def not_div(n):

    return b//n  - (a-1) //n

print((not_div(1)-not_div(c)-not_div(d)+not_div(c*d//my_gcd(c,d)))) 
def gcd(i, j):
    if i > j:
        tmp = i
        i = j
        j = tmp
    while i != 0:
        tmp = i
        i = j % i
        j = tmp
    return j


def lcm(i, j):
    return i * j // gcd(i, j)


def main():
    a, b, c, d = list(map(int, input().split()))
    ans = b - a + 1
    ans -= (
        (b // c - (a - 1) // c)
        + (b // d - (a - 1) // d)
        - (b // lcm(c, d) - (a - 1) // lcm(c, d))
    )
    print(ans)


main()

#!/usr/bin/env python3
a, b, c, d = list(map(int, input().split()))


def my_gcd(i, j):
    if i > j:
        i, j = j, i
    while i != 0:
        if j % i != 0:
            i, j = j % i, i
        else:
            return i


def not_div(n):
    return b // n - (a - 1) // n


print((not_div(1) - not_div(c) - not_div(d) + not_div(c * d // my_gcd(c, d))))

-def gcd(i, j): -    if i > j: -        tmp = i -        i = j -        j = tmp -    while i != 0: -        tmp = i -        i = j % i -        j = tmp -    return j +#!/usr/bin/env python3 +a, b, c, d = list(map(int, input().split())) -def lcm(i, j): -    return i * j // gcd(i, j) +def my_gcd(i, j): +    if i > j: +        i, j = j, i +    while i != 0: +        if j % i != 0: +            i, j = j % i, i +        else: +            return i -def main(): -    a, b, c, d = list(map(int, input().split())) -    ans = b - a + 1 -    ans -= ( -        (b // c - (a - 1) // c) -        + (b // d - (a - 1) // d) -        - (b // lcm(c, d) - (a - 1) // lcm(c, d)) -    ) -    print(ans) +def not_div(n): +    return b // n - (a - 1) // n -main() +print((not_div(1) - not_div(c) - not_div(d) + not_div(c * d // my_gcd(c, d))))