A, B, C, D=(int(x) for x in input().split(" "))

import fractions



def eks(x,a):

    return a//x



def wai(x):

    return eks(x,B)-eks(x,A-1)



def lcm(a,b):

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



zet=B-A+1-(wai(C)+wai(D)-wai(lcm(C,D)))

print (zet)


A,B,C,D=(int(x) for x in input().split(" "))

def gcd(x,y): 

  

   while(y): 

        x, y = y, x % y 

  

   return x 

def nb_divisers(n,m):

    return n//m

def nb_d_btw(f,g,n):

    if f%n==0:

        return nb_divisers(g,n)-nb_divisers(f,n)+1

    else:

        return nb_divisers(g,n)-nb_divisers(f,n)

def nb_notdivisers_f(a,b,c,d):

    e=int(c*d/gcd(c,d))

    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))

print((nb_notdivisers_f(A,B,C,D)))
A, B, C, D = (int(x) for x in input().split(" "))
import fractions


def eks(x, a):
    return a // x


def wai(x):
    return eks(x, B) - eks(x, A - 1)


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


zet = B - A + 1 - (wai(C) + wai(D) - wai(lcm(C, D)))
print(zet)

A, B, C, D = (int(x) for x in input().split(" "))


def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def nb_divisers(n, m):
    return n // m


def nb_d_btw(f, g, n):
    if f % n == 0:
        return nb_divisers(g, n) - nb_divisers(f, n) + 1
    else:
        return nb_divisers(g, n) - nb_divisers(f, n)


def nb_notdivisers_f(a, b, c, d):
    e = int(c * d / gcd(c, d))
    return b - a + 1 - (nb_d_btw(a, b, c) + nb_d_btw(a, b, d) - nb_d_btw(a, b, e))


print((nb_notdivisers_f(A, B, C, D)))

-import fractions -def eks(x, a): -    return a // x +def gcd(x, y): +    while y: +        x, y = y, x % y +    return x -def wai(x): -    return eks(x, B) - eks(x, A - 1) +def nb_divisers(n, m): +    return n // m -def lcm(a, b): -    return a * b // fractions.gcd(a, b) +def nb_d_btw(f, g, n): +    if f % n == 0: +        return nb_divisers(g, n) - nb_divisers(f, n) + 1 +    else: +        return nb_divisers(g, n) - nb_divisers(f, n) -zet = B - A + 1 - (wai(C) + wai(D) - wai(lcm(C, D))) -print(zet) +def nb_notdivisers_f(a, b, c, d): +    e = int(c * d / gcd(c, d)) +    return b - a + 1 - (nb_d_btw(a, b, c) + nb_d_btw(a, b, d) - nb_d_btw(a, b, e)) + + +print((nb_notdivisers_f(A, B, C, D)))