from fractions import gcd

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

lenth=b-a+1



def lcm(m,n):

	return (m*n)//gcd(m,n)



def divnumber(c):

	ans=lenth//c

	rem1=a%c

	if rem1==0:rem1+=c

	rem2=lenth%c-1

	if rem1+rem2>=c:

		ans+=1

	return ans



print((lenth-divnumber(c)-divnumber(d)+divnumber(lcm(c,d))))

	
import sys, math, itertools, collections, bisect

input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')

inf = float('inf') ;mod = 10**9+7

mans = inf ;ans = 0 ;count = 0 ;pro = 1



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

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

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

def gcd(a, b):

    while(b != 0):

        a, b = b, a % b

    return a

    

def lcm(m,n):

    return (m*n)//gcd(m,n)

cd = lcm(c,d)

CD = b//cd - (a-1)//cd

print((b-a+1-C-D+CD))

# print(C,D,CD)
from fractions import gcd

a, b, c, d = list(map(int, input().split()))
lenth = b - a + 1


def lcm(m, n):
    return (m * n) // gcd(m, n)


def divnumber(c):
    ans = lenth // c
    rem1 = a % c
    if rem1 == 0:
        rem1 += c
    rem2 = lenth % c - 1
    if rem1 + rem2 >= c:
        ans += 1
    return ans


print((lenth - divnumber(c) - divnumber(d) + divnumber(lcm(c, d))))

import sys, math, itertools, collections, bisect

input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
a, b, c, d = list(map(int, input().split()))
C = b // c - (a - 1) // c
D = b // d - (a - 1) // d


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


def lcm(m, n):
    return (m * n) // gcd(m, n)


cd = lcm(c, d)
CD = b // cd - (a - 1) // cd
print((b - a + 1 - C - D + CD))
# print(C,D,CD)

-from fractions import gcd +import sys, math, itertools, collections, bisect +input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") +inf = float("inf") +mod = 10**9 + 7 +mans = inf +ans = 0 +count = 0 +pro = 1 -lenth = b - a + 1 +C = b // c - (a - 1) // c +D = b // d - (a - 1) // d + + +def gcd(a, b): +    while b != 0: +        a, b = b, a % b +    return a -def divnumber(c): -    ans = lenth // c -    rem1 = a % c -    if rem1 == 0: -        rem1 += c -    rem2 = lenth % c - 1 -    if rem1 + rem2 >= c: -        ans += 1 -    return ans - - -print((lenth - divnumber(c) - divnumber(d) + divnumber(lcm(c, d)))) +cd = lcm(c, d) +CD = b // cd - (a - 1) // cd +print((b - a + 1 - C - D + CD)) +# print(C,D,CD)