from fractions import gcd

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



lcm = c*d // gcd(c,d)



def calc(x):

    return x-(x//c)-(x//d)+(x//lcm)



print((calc(b)-calc(a-1)))
import sys

input = sys.stdin.readline

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



def gcd(a,b):

    while b:

        a, b = b, a%b

    return a



def lcm(a,b):

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



def calc(x):

    return x-(x//c)-(x//d)+(x//lcm(c,d))



print((calc(b)-calc(a-1)))
from fractions import gcd

a, b, c, d = list(map(int, input().split()))
lcm = c * d // gcd(c, d)


def calc(x):
    return x - (x // c) - (x // d) + (x // lcm)


print((calc(b) - calc(a - 1)))

import sys

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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def calc(x):
    return x - (x // c) - (x // d) + (x // lcm(c, d))


print((calc(b) - calc(a - 1)))

-from fractions import gcd +import sys +input = sys.stdin.readline -lcm = c * d // gcd(c, d) + + +def gcd(a, b): +    while b: +        a, b = b, a % b +    return a + + +def lcm(a, b): +    return a * b // gcd(a, b) -    return x - (x // c) - (x // d) + (x // lcm) +    return x - (x // c) - (x // d) + (x // lcm(c, d))