def gcd(x,y):

	while y:

		x,y = y,x % y

	return x





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

ans = 0



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



if a%c == 0:

	start_c = a

else:

	start_c = a + c - a % c

if a%d == 0:

	start_d = a

else:

	start_d = a + d - a % d

if a%cd == 0:

	start_cd = a

else:

	start_cd = a + cd - a % cd



end_c = b - b % c

end_d = b - b % d

end_cd = b - b % cd



if b >= c:

	ans += (end_c - start_c) // c + 1

if b >= d:

	ans += (end_d - start_d) // d + 1

if b >= cd:

	ans -= (end_cd - start_cd) // cd + 1



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

import math

from decimal import *

getcontext().prec = 50

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



from functools import reduce

def gcd(a,b):

  if a < b:

    a, b = b, a

  while a % b != 0:

    a, b = b, a % b

  return b



def lcm_base(x, y):

  return (x * y) // gcd(x, y)



def lcm_list(numbers):

  return reduce(lcm_base, numbers, 1)



gcd = lcm_list([c,d])



def solve(n):

	start = n * math.ceil(Decimal(a) / Decimal(n))

	end = n * (Decimal(b) // Decimal(n))

	#print(start,end)

	return (end - start) // n + 1



#print(solve(c),solve(d),solve(gcd))

ans = solve(c) + solve(d) - solve(gcd)

#print(ans)

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

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


a, b, c, d = list(map(int, input().split()))
ans = 0
cd = c * d // gcd(c, d)
if a % c == 0:
    start_c = a
else:
    start_c = a + c - a % c
if a % d == 0:
    start_d = a
else:
    start_d = a + d - a % d
if a % cd == 0:
    start_cd = a
else:
    start_cd = a + cd - a % cd
end_c = b - b % c
end_d = b - b % d
end_cd = b - b % cd
if b >= c:
    ans += (end_c - start_c) // c + 1
if b >= d:
    ans += (end_d - start_d) // d + 1
if b >= cd:
    ans -= (end_cd - start_cd) // cd + 1
print((b - a + 1 - ans))

import math
from decimal import *

getcontext().prec = 50
a, b, c, d = list(map(int, input().split()))
from functools import reduce


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


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


gcd = lcm_list([c, d])


def solve(n):
    start = n * math.ceil(Decimal(a) / Decimal(n))
    end = n * (Decimal(b) // Decimal(n))
    # print(start,end)
    return (end - start) // n + 1


# print(solve(c),solve(d),solve(gcd))
ans = solve(c) + solve(d) - solve(gcd)
# print(ans)
print((b - a - ans + 1))

-def gcd(x, y): -    while y: -        x, y = y, x % y -    return x +import math +from decimal import * + +getcontext().prec = 50 +a, b, c, d = list(map(int, input().split())) +from functools import reduce -a, b, c, d = list(map(int, input().split())) -ans = 0 -cd = c * d // gcd(c, d) -if a % c == 0: -    start_c = a -else: -    start_c = a + c - a % c -if a % d == 0: -    start_d = a -else: -    start_d = a + d - a % d -if a % cd == 0: -    start_cd = a -else: -    start_cd = a + cd - a % cd -end_c = b - b % c -end_d = b - b % d -end_cd = b - b % cd -if b >= c: -    ans += (end_c - start_c) // c + 1 -if b >= d: -    ans += (end_d - start_d) // d + 1 -if b >= cd: -    ans -= (end_cd - start_cd) // cd + 1 -print((b - a + 1 - ans)) +def gcd(a, b): +    if a < b: +        a, b = b, a +    while a % b != 0: +        a, b = b, a % b +    return b + + +def lcm_base(x, y): +    return (x * y) // gcd(x, y) + + +def lcm_list(numbers): +    return reduce(lcm_base, numbers, 1) + + +gcd = lcm_list([c, d]) + + +def solve(n): +    start = n * math.ceil(Decimal(a) / Decimal(n)) +    end = n * (Decimal(b) // Decimal(n)) +    # print(start,end) +    return (end - start) // n + 1 + + +# print(solve(c),solve(d),solve(gcd)) +ans = solve(c) + solve(d) - solve(gcd) +# print(ans) +print((b - a - ans + 1))