A,B,C,D = [int(i) for i in input().split()]



def gcd(a,b):

    while b!=0:

        a,b=b,a%b

    return a



def lcm(a,b):

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



E = lcm(C,D)



p = B-A+1



ac = p//C

if A%C+p%C >= C+1:

    ac += 1



ad = p//D

if A%D+p%D >= D+1:

    ad += 1



ae = p//E

if A%E+p%E >= E+1:

    ae += 1



print((p-(ac+ad-ae)))

from fractions import gcd



def lcm(a,b):

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



A,B,C,D = [int(zz) for zz in input().split()]



bc = B//C

ac = (A-1)//C

bd = B//D

ad = (A-1)//D

bcd = B//lcm(C,D)

acd = (A-1)//lcm(C,D)



print((B-A-bc+ac-bd+ad+bcd-acd+1))

A, B, C, D = [int(i) for i in input().split()]


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


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


E = lcm(C, D)
p = B - A + 1
ac = p // C
if A % C + p % C >= C + 1:
    ac += 1
ad = p // D
if A % D + p % D >= D + 1:
    ad += 1
ae = p // E
if A % E + p % E >= E + 1:
    ae += 1
print((p - (ac + ad - ae)))

from fractions import gcd


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


A, B, C, D = [int(zz) for zz in input().split()]
bc = B // C
ac = (A - 1) // C
bd = B // D
ad = (A - 1) // D
bcd = B // lcm(C, D)
acd = (A - 1) // lcm(C, D)
print((B - A - bc + ac - bd + ad + bcd - acd + 1))

-A, B, C, D = [int(i) for i in input().split()] - - -def gcd(a, b): -    while b != 0: -        a, b = b, a % b -    return a +from fractions import gcd -E = lcm(C, D) -p = B - A + 1 -ac = p // C -if A % C + p % C >= C + 1: -    ac += 1 -ad = p // D -if A % D + p % D >= D + 1: -    ad += 1 -ae = p // E -if A % E + p % E >= E + 1: -    ae += 1 -print((p - (ac + ad - ae))) +A, B, C, D = [int(zz) for zz in input().split()] +bc = B // C +ac = (A - 1) // C +bd = B // D +ad = (A - 1) // D +bcd = B // lcm(C, D) +acd = (A - 1) // lcm(C, D) +print((B - A - bc + ac - bd + ad + bcd - acd + 1))