from fractions import gcd

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

count=0

x=b-a+1

def cal(x):

    return x//c+x//d-x//(c*d//gcd(c,d))

print((b-a+1-(cal(b)-cal(a-1))))

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



def gcd(a, b): #最大公約数

    while b:

        a, b = b, a%b

    return a



A, B, C, D = lr()

cnt_divided_C = B // C - (A-1) // C

cnt_divided_D = B // D - (A-1) // D

x = C * D // gcd(C, D)

cnt_divided_CD = B // x - (A-1) // x

answer = B - (A-1) - (cnt_divided_C + cnt_divided_D - cnt_divided_CD)

print(answer)
from fractions import gcd

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


def cal(x):
    return x // c + x // d - x // (c * d // gcd(c, d))


print((b - a + 1 - (cal(b) - cal(a - 1))))

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


A, B, C, D = lr()
cnt_divided_C = B // C - (A - 1) // C
cnt_divided_D = B // D - (A - 1) // D
x = C * D // gcd(C, D)
cnt_divided_CD = B // x - (A - 1) // x
answer = B - (A - 1) - (cnt_divided_C + cnt_divided_D - cnt_divided_CD)
print(answer)

-from fractions import gcd +import sys -a, b, c, d = list(map(int, input().split())) -count = 0 -x = b - a + 1 +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) -def cal(x): -    return x // c + x // d - x // (c * d // gcd(c, d)) +def gcd(a, b):  # 最大公約数 +    while b: +        a, b = b, a % b +    return a -print((b - a + 1 - (cal(b) - cal(a - 1)))) +A, B, C, D = lr() +cnt_divided_C = B // C - (A - 1) // C +cnt_divided_D = B // D - (A - 1) // D +x = C * D // gcd(C, D) +cnt_divided_CD = B // x - (A - 1) // x +answer = B - (A - 1) - (cnt_divided_C + cnt_divided_D - cnt_divided_CD) +print(answer)