You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

-----Constraints-----
 - 1\leq A\leq B\leq 10^{18}
 - 1\leq C,D\leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
A B C D

-----Output-----
Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

-----Sample Input-----
4 9 2 3

-----Sample Output-----
2

5 and 7 satisfy the condition.

Difficulty: EASY

Solutions:
import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(A, B, C, D) = list(map(int, input().split()))
l = lcm(C, D)
temp = l - (l // C + l // D - 1)
a = (A - 1) % l
b = B % l
aa = (A - 1) // l
bb = B // l
tempA = a - (a // C + a // D - 1)
tempB = b - (b // C + b // D - 1)
ans = temp * bb + tempB - (temp * aa + tempA)
print(ans)


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(A, B, C, D) = map(int, input().split())
x = B // lcm(C, D) - (A - 1) // lcm(C, D)
y = B // C - (A - 1) // C
z = B // D - (A - 1) // D
ans = B - A + 1 - (y + z - x)
print(ans)


import math
(a, b, c, d) = map(int, input().split())
lcm = c * d // math.gcd(c, d)
print(b - (b // c + b // d - b // lcm) - (a - 1 - ((a - 1) // d + (a - 1) // c - (a - 1) // lcm)))


import math
(A, B, C, D) = map(int, input().split())
E = C * D // math.gcd(C, D)
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
e = B // E - (A - 1) // E
print(B - A + 1 - c - d + e)


import math
(A, B, C, D) = map(int, input().split())
if A % C == 0:
	divC = B // C - A // C + 1
else:
	divC = B // C - A // C
if A % D == 0:
	divD = B // D - A // D + 1
else:
	divD = B // D - A // D
lcm = C * D // math.gcd(C, D)
if A % lcm == 0:
	divlcm = B // lcm - A // lcm + 1
else:
	divlcm = B // lcm - A // lcm
print(B - A + 1 - divC - divD + divlcm)


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

def LI():
	return list(map(int, input().split()))

def TI():
	return tuple(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def gcd2(i, past):
	return i * past // math.gcd(i, past)

def main():
	(A, B, C, D) = MI()
	AC = (A - 1) // C
	BC = B // C
	AD = (A - 1) // D
	BD = B // D
	ACD = (A - 1) // gcd2(C, D)
	BCD = B // gcd2(C, D)
	ans = BC + BD - BCD - (AC + AD - ACD)
	print(B - A + 1 - ans)

def __starting_point():
	main()
__starting_point()


import math
[A, B, C, D] = [int(i) for i in input().split()]
u = int(C * D / math.gcd(C, D))
s = B // C - A // C + B // D - A // D - B // u + A // u + 1
t = 0
if A % C != 0:
	t -= 1
if A % D != 0:
	t -= 1
if A % u != 0:
	t += 1
s += t
ans = B - A + 1 - s
print(ans)


import math
(A, B, C, D) = map(int, input().split())

def X(x):
	c = x // C
	d = x // D
	l = C * D // math.gcd(C, D)
	return x - c - d + x // l
print(X(B) - X(A - 1))


import math
(a, b, c, d) = list(map(int, input().split()))
gcd = c * d // math.gcd(c, d)
r = b // c + b // d - b // gcd
l = (a - 1) // c + (a - 1) // d - (a - 1) // gcd
print(b - a - (r - l) + 1)


import math
(a, b, c, d) = map(int, input().split())
l = c * d // math.gcd(c, d)

def cnt(x):
	return b // x - a // x + int(a % x == 0)
print(b - a + 1 - cnt(c) - cnt(d) + cnt(l))


(A, B, C, D) = map(int, input().split())
f = C
g = D
while f % g != 0:
	(f, g) = [g, f % g]
l = C * D // g
m = B // l
n = (A - 1) // l
print(B - B // C - B // D + m - (A - 1 - (A - 1) // C - (A - 1) // D + n))


from fractions import *
(a, b, c, d) = map(int, input().split())
f = lambda x: x - x // c - x // d + x // (c * d // gcd(c, d))
print(f(b) - f(a - 1))


import math
(a, b, c, d) = list(map(int, input().split()))
lcm = c * d // math.gcd(c, d)
a2 = a - (a // c + a // d - a // lcm)
b2 = b - (b // c + b // d - b // lcm)
print(b2 - a2 if a % c == 0 or a % d == 0 else b2 - a2 + 1)


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	(A, B, C, D) = LI()

	def f(X):
		ret = X - X // C - X // D + X // (C * D // math.gcd(C, D))
		return ret
	ans = f(B) - f(A - 1)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(A, B, C, D) = map(int, input().split())
Cres = B // C - (A - 1) // C
Dres = B // D - (A - 1) // D
CDres = B // lcm(C, D) - (A - 1) // lcm(C, D)
print(B - A + 1 - (Cres + Dres - CDres))


import math
import collections
import itertools
import copy

def YesNo(Bool):
	if Bool:
		print('Yes')
	else:
		print('No')
	return

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

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

def resolve():
	(A, B, C, D) = list(map(int, input().split()))
	Cmin = (A - 1) // C
	Dmin = (A - 1) // D
	Cmax = B // C
	Dmax = B // D
	LCM = lcm(C, D)
	LCMmin = (A - 1) // LCM
	LCMmax = B // LCM
	Cnum = Cmax - Cmin
	Dnum = Dmax - Dmin
	LCMnum = LCMmax - LCMmin
	ans = B - (A - 1) - Cnum - Dnum + LCMnum
	print(ans)
resolve()


import math
(A, B, C, D) = map(int, input().split())
g = C * D // math.gcd(C, D)
print(B - A + 1 - (B // C - -(-A // C) + 1) - (B // D - -(-A // D) + 1) + (B // g - -(-A // g) + 1))


from math import gcd
(a, b, c, d) = map(int, input().split())
e = c // gcd(c, d) * d
cnt = lambda n: n // c + n // d - n // e
print(b - a + 1 - cnt(b) + cnt(a - 1))


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

def lcm(a, b):
	y = a * b / math.gcd(a, b)
	return int(y)
x = b - a + 1
cc = b // c - (a - 1) // c
dd = b // d - (a - 1) // d
cd = lcm(c, d)
cd = b // cd - (a - 1) // cd
wa = cc - cd + dd
print(x - wa)


import math
(a, b, c, d) = list(map(int, input().split()))
s1 = b // c - (a - 1) // c
s2 = b // d - (a - 1) // d
s12 = b // (c * d // math.gcd(c, d)) - (a - 1) // (c * d // math.gcd(c, d))
print(b - a + 1 - (s1 + s2 - s12))


import math
(a, b, c, d) = list(map(int, input().split()))
GCD = math.gcd(c, d)
LCM = c * d // GCD
print(b - b // c - b // d + b // LCM - a + 1 + (a - 1) // c + (a - 1) // d - (a - 1) // LCM)


import math
(A, B, C, D) = map(int, input().split())
lcm = C * D // math.gcd(C, D)
a = B - A + 1
b = B // C - (A - 1) // C
c = B // D - (A - 1) // D
d = B // lcm - (A - 1) // lcm
print(a - b - c + d)


import math
(A, B, C, D) = list(map(int, input().split()))
cd = C * D // math.gcd(C, D)
(pac, qac) = divmod(A, C)
(pad, qad) = divmod(A, D)
(pacd, qacd) = divmod(A, cd)
(pbc, qbc) = divmod(B, C)
(pbd, qbd) = divmod(B, D)
(pbcd, qbcd) = divmod(B, cd)
pac = pac - 1 if qac == 0 else pac
pad = pad - 1 if qad != 0 else pad
pacd = pacd - 1 if qacd != 0 else pacd
ans = pbc + pbd - pbcd - (pac + pad - pacd)
print(B - A - ans + 1)


from math import gcd

def f(x):
	return x - (x // C + x // D - x // lcm)
(A, B, C, D) = list(map(int, input().split()))
lcm = C * D // gcd(C, D)
print(f(B) - f(A - 1))


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

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

def main():
	(A, B, C, D) = map(int, input().split())
	E = lcm(C, D)
	(a_c, a_d, a_cd) = ((A - 1) // C, (A - 1) // D, (A - 1) // E)
	(b_c, b_d, b_cd) = (B // C, B // D, B // E)
	(a, b) = (a_c + a_d - a_cd, b_c + b_d - b_cd)
	ans = B - A + 1 - (b - a)
	print(ans)
main()


import math
(a, b, c, d) = map(int, input().split())
C = b // c - (a - 1) // c
D = b // d - (a - 1) // d
x = c * d // math.gcd(c, d)
CD = b // x - (a - 1) // x
print(b - a + 1 - (C + D - CD))


import math
(A, B, C, D) = list(map(int, input().split()))

def lcm(x, y):
	return x * y // math.gcd(x, y)
lcm = lcm(C, D)
u_b_ans = B // C + B // D - B // lcm
u_a_ans = (A - 1) // C + (A - 1) // D - (A - 1) // lcm
print(B - A + 1 - u_b_ans + u_a_ans)


import math
(a, b, c, d) = map(int, input().split())
divc = b // c - (a - 1) // c
divd = b // d - (a - 1) // d
cd = b // (c * d // math.gcd(c, d)) - (a - 1) // (c * d // math.gcd(c, d))
print(b - a - divc - divd + cd + 1)


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

def f(x, y):
	return x * y // math.gcd(x, y)
z = f(c, d)
print(b - a + 1 - (b // c - (a - 1) // c + (b // d - (a - 1) // d) - (b // z - (a - 1) // z)))


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(A, B, C, D) = list(map(int, input().split()))
bc = B // C
ac = (A - 1) // C
cnum = bc - ac
bd = B // D
ad = (A - 1) // D
dnum = bd - ad
lcmcd = lcm(C, D)
blcmcd = B // lcmcd
alcmcd = (A - 1) // lcmcd
lcmcdnum = blcmcd - alcmcd
print(B - A - cnum - dnum + lcmcdnum + 1)


(a, b, c, d) = map(int, input().split())
divc = b // c - (a - 1) // c
divd = b // d - (a - 1) // d
import math
l = c * d // math.gcd(c, d)
divl = b // l - (a - 1) // l
print(b - a + 1 - divc - divd + divl)


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(A, B, C, D) = map(int, input().split())
ans = 0
Ac = (A - 1) // C
Ad = (A - 1) // D
Acd = (A - 1) // lcm(C, D)
Bc = B // C
Bd = B // D
Bcd = B // lcm(C, D)
c = Bc - Ac
d = Bd - Ad
cd = Bcd - Acd
print(B - A + 1 - (c + d - cd))


import math
(a, b, c, d) = map(int, input().split())
a -= 1
h = int(c * d / math.gcd(c, d))
e = b // c - a // c
f = b // d - a // d
g = b // h - a // h
print(b - a - e - f + g)


import math as m
(A, B, C, D) = map(int, input().split())
A -= 1
g = C * D // m.gcd(C, D)
x = B // C - A // C
y = B // D - A // D
z = B // g - A // g
print(B - A - x - y + z)


import math
(A, B, C, D) = list(map(int, input().split()))
lcm = C * D // math.gcd(C, D)

def num_multi(num, lb, ub):
	lR = lb // num
	lQ = lb % num
	uR = ub // num
	ans = uR - lR
	if lQ == 0:
		ans += 1
	return ans
print(B - A + 1 - num_multi(C, A, B) - num_multi(D, A, B) + num_multi(lcm, A, B))


def gcd(m, n):
	if n == 0:
		return m
	return gcd(n, m % n)

def main():
	(A, B, C, D) = list(map(int, input().split()))
	ans = B - A + 1
	ans -= B // C + B // D
	ans += (A - 1) // C + (A - 1) // D
	lcm = C // gcd(C, D) * D
	ans += B // lcm - (A - 1) // lcm
	print(ans)

def __starting_point():
	main()
__starting_point()


import math
(A, B, C, D) = map(int, input().split())

def F(N):
	x = N // C
	x += N // D
	lcm = C * D // math.gcd(C, D)
	x -= N // lcm
	return N - x
answer = F(B) - F(A - 1)
print(answer)


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(a, b, c, d) = map(int, input().split())
c_div = b // c - (a - 1) // c
d_div = b // d - (a - 1) // d
cd_div = b // lcm(c, d) - (a - 1) // lcm(c, d)
ans = b - a + 1 - (c_div + d_div - cd_div)
print(ans)


import sys
import math
(a, b, c, d) = map(int, sys.stdin.readline().split())
lcm = c * d // math.gcd(c, d)
div_c = b // c - (a - 1) // c
div_d = b // d - (a - 1) // d
div_lcm = b // lcm - (a - 1) // lcm
print(b - a + 1 - div_c - div_d + div_lcm)


import math

def lcm(a):
	LCM = a[0]
	for i in range(1, len(a)):
		LCM = LCM * a[i] // math.gcd(LCM, a[i])
	return LCM

def f(k):
	return b // k - (a - 1) // k
(a, b, c, d) = map(int, input().split())
ALL = b - a + 1
ans = ALL - (f(c) + f(d) - f(lcm([c, d])))
print(ans)


from math import gcd
(a, b, c, d) = map(int, input().split())
t = c * d // gcd(c, d)
x = a - 1 - ((a - 1) // c + (a - 1) // d) + (a - 1) // t
y = b - (b // c + b // d) + b // t
print(y - x)


import math
(a, b, c, d) = map(int, input().split())
l = c * d // math.gcd(c, d)
u = b // c + b // d - b // l
l = (a - 1) // c + (a - 1) // d - (a - 1) // l
print(b - a + 1 - u + l)


from math import gcd
(a, b, c, d) = map(int, input().split())
lcm = c * d // gcd(c, d)
a -= 1
p = b // c - a // c
q = b // d - a // d
r = b // lcm - a // lcm
a += 1
print(b - a + 1 - (p + q - r))


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)

def f(x, c, d):
	res = x
	res -= x // c
	res -= x // d
	res += x // lcm(c, d)
	return res
(a, b, c, d) = map(int, input().split())
ans = f(b, d, c) - f(a - 1, c, d)
print(ans)


(a, b, c, d) = map(int, input().split())
from math import gcd
lcm = c * d // gcd(c, d)
b_div_c = b // c
a_div_c = (a - 1) // c
b_div_d = b // d
a_div_d = (a - 1) // d
b_div_cd = b // lcm
a_div_cd = (a - 1) // lcm
ans1 = b_div_c - a_div_c
ans2 = b_div_d - a_div_d
ans3 = b_div_cd - a_div_cd
ans = b - (a - 1) - ans1 - ans2 + ans3
print(ans)


import sys
import math
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	(a, b, c, d) = inl()
	cd = c * d // math.gcd(c, d)
	r1 = b // c + b // d - b // cd
	r2 = (a - 1) // c + (a - 1) // d - (a - 1) // cd
	ans = b - r1 - (a - 1 - r2)
	return ans
print(solve())


import math
(A, B, C, D) = list(map(int, input().split()))
E = int(C * D / math.gcd(C, D))
print(B - A + 1 - (B // C - (A - 1) // C) - (B // D - (A - 1) // D) + B // E - (A - 1) // E)


from math import gcd
(A, B, C, D) = map(int, input().split())
lcm = C * D // gcd(C, D)
a = (A - 1) // C + (A - 1) // D - (A - 1) // lcm
b = B // C + B // D - B // lcm
print(B - A + 1 - b + a)


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(a, b, c, d) = map(int, input().split())
e = lcm(c, d)
print(b - a + 1 - (b // c - (a - 1) // c) - (b // d - (a - 1) // d) + (b // e - (a - 1) // e))


import math
(a, b, c, d) = map(int, input().split())
mc = b // c - (a - 1) // c
md = b // d - (a - 1) // d
cd = c * d // math.gcd(c, d)
mcd = b // cd - (a - 1) // cd
print(b - a + 1 - mc - md + mcd)


import sys
import math
(A, B, C, D) = map(int, sys.stdin.readline().split())
lcm = C * D // math.gcd(C, D)
bc = B // C
bd = B // D
bg = B // lcm
ac = (A - 1) // C
ad = (A - 1) // D
ag = (A - 1) // lcm
print(B - A + 1 - (bc - ac) - (bd - ad) + (bg - ag))


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)

def main():
	(A, B, C, D) = list(map(int, input().split()))
	tmpC = (A - 1) // C
	tmpC2 = B // C
	numC = tmpC2 - tmpC
	tmpD = (A - 1) // D
	tmpD2 = B // D
	numD = tmpD2 - tmpD
	if C == D:
		ans = B - A + 1 - numC
	else:
		tmpCD = (A - 1) // lcm(C, D)
		tmpCD2 = B // lcm(C, D)
		numCD = tmpCD2 - tmpCD
		ans = B - A + 1 - numC - numD + numCD
	return ans
print(main())


import math
INT = lambda : int(input())
INTM = lambda : map(int, input().split())
STRM = lambda : map(str, input().split())
STR = lambda : str(input())
LIST = lambda : list(map(int, input().split()))
LISTS = lambda : list(map(str, input().split()))

def do():
	(a, b, c, d) = INTM()
	lcm = c * d // math.gcd(c, d)
	a -= 1
	ct_a = a - a // c - a // d + a // lcm
	ct_b = b - b // c - b // d + b // lcm
	print(ct_b - ct_a)

def __starting_point():
	do()
__starting_point()


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

def lcm(a, b):
	return a * b // gcd(a, b)
(A, B, C, D) = map(int, input().split())

def div(x):
	num = x
	num -= x // C
	num -= x // D
	num += x // lcm(C, D)
	return num
print(div(B) - div(A - 1))


import math
(a, b, c, d) = map(int, input().split())
cyaku = b // c
dyaku = b // d
cds = b // (c * d // math.gcd(c, d))
x = b - (cyaku + dyaku - cds)
cyaku2 = (a - 1) // c
dyaku2 = (a - 1) // d
cds2 = (a - 1) // (c * d // math.gcd(c, d))
y = a - 1 - (cyaku2 + dyaku2 - cds2)
print(x - y)


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(A, B, C, D) = map(int, input().split())
CD_lcm = lcm(C, D)
B_s = B - B // C - B // D + B // CD_lcm
A_s = A - 1 - (A - 1) // C - (A - 1) // D + (A - 1) // CD_lcm
print(B_s - A_s)


import math
(A, B, C, D) = list(map(int, input().split()))
nad = B // D
nac = B // C
nid = (A - 1) // D
nic = (A - 1) // C
nacd = B // (D * C // math.gcd(D, C))
nicd = (A - 1) // (D * C // math.gcd(D, C))
ans = B - A + 1 - (nad - nid) - (nac - nic) + (nacd - nicd)
print(int(ans))


import math
(A, B, C, D) = map(int, input().split())
calc = lambda x: B // x - (A - 1) // x
print(B - A + 1 - calc(C) - calc(D) + calc(C * D // math.gcd(C, D)))


from math import *
(A, B, C, D) = map(int, input().split())
mc = B // C - (A - 1) // C
md = B // D - (A - 1) // D
cd = C * D // gcd(C, D)
mcd = B // cd - (A - 1) // cd
print(B - A + 1 - mc - md + mcd)


import math
(A, B, C, D) = map(int, input().split())
LCD = C * D // math.gcd(C, D)
ans = B - (B // C + B // D - B // LCD) - (A - 1 - ((A - 1) // C + (A - 1) // D - (A - 1) // LCD))
print(int(ans))


import math
(a, b, c, d) = map(int, input().split())
l = c * d // math.gcd(c, d)
all = b - a + 1
can_c = b // c - (a - 1) // c
can_d = b // d - (a - 1) // d
can_cd = b // l - (a - 1) // l
ans = all - can_c - can_d + can_cd
print(ans)


import os
import sys

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

def main():
	(a, b, c, d) = list(map(int, input().split()))
	if (a / c).is_integer():
		c_cnt = b // c - a // c + 1
	else:
		c_cnt = b // c - a // c
	if (a / d).is_integer():
		d_cnt = b // d - a // d + 1
	else:
		d_cnt = b // d - a // d
	lcm = c * d // gcd(max(c, d), min(c, d))
	if (a / lcm).is_integer():
		lcm_cnt = b // lcm - a // lcm + 1
	else:
		lcm_cnt = b // lcm - a // lcm
	print(b - a + 1 - c_cnt - d_cnt + lcm_cnt)

def __starting_point():
	main()
__starting_point()


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

def calc(x):
	nonlocal c, d
	l = c // math.gcd(c, d) * d
	return x - x // c - x // d + x // l
print(calc(b) - calc(a - 1))


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

def yakusuu(n):
	return n // c + n // d - n // (c * d // math.gcd(c, d))
print(int(b - a + 1 - (yakusuu(b) - yakusuu(a - 1))))


import math
(a, b, c, d) = map(int, input().split())
e = c * d // math.gcd(c, d)
wa = 0
c_seki = b // c - (a - 1) // c
d_seki = b // d - (a - 1) // d
e_seki = b // e - (a - 1) // e
wa = c_seki + d_seki - e_seki
print(b - a + 1 - wa)


(a, b, c, d) = map(int, input().split())
from math import gcd

def cnt(n):
	lcm = c // gcd(c, d) * d
	return n - n // c - n // d + n // lcm
print(cnt(b) - cnt(a - 1))


import math
(a, b, c, d) = map(int, input().split())
split_b = b - b // c - b // d + b // (c * d // math.gcd(c, d))
split_a = a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // (c * d // math.gcd(c, d))
print(split_b - split_a)


(a, b, c, d) = map(int, input().split())
a -= 1
e = c
f = d
while f > 0:
	(e, f) = (f, e % f)
x = b // c + b // d - b // (c * d // e)
y = a // c + a // d - a // (c * d // e)
print(b - x - a + y)


from math import gcd as g
(a, b, c, d) = map(int, input().split())
count = 0
print(b - a + 1 - (b // c - (a - 1) // c + b // d - (a - 1) // d - b // (c * d // g(c, d)) + (a - 1) // (c * d // g(c, d))))


def gcd(x, y):
	if y == 0:
		return x
	r = x % y
	return gcd(y, r)
(A, B, C, D) = [int(x) for x in input().split()]
if C > D:
	E = C * D // gcd(C, D)
else:
	E = C * D // gcd(D, C)
divC = B // C - (A - 1) // C
divD = B // D - (A - 1) // D
divE = B // E - (A - 1) // E
div = divC + divD - divE
ans = B - A + 1 - div
print(ans)


from math import gcd

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

def getExclude(x, c, d):
	return x - x // c - x // d + x // lcm(c, d)
(a, b, c, d) = (int(x) for x in input().split())
ans = getExclude(b, c, d) - getExclude(a - 1, c, d)
print(ans)


import math
(a, b, c, d) = map(int, input().split())
m = b // c + -a // c
n = b // d + -a // d
g = c * d // math.gcd(c, d)
p = b // g + -a // g
print(b - a + 1 - (m + 1 + n + 1 - (p + 1)))


(A, B, C, D) = map(int, input().split())
A -= 1
import math
g = C * D // math.gcd(C, D)
a = A // C + A // D - A // g
b = B // C + B // D - B // g
ans = B - A - b + a
print(ans)


(a, b, c, d) = map(int, input().split())
import math
min = int(c * d / math.gcd(c, d))
x = b - b // c - b // d + b // min
y = a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // min
print(int(x - y))


import math
(a, b, c, d) = list(map(int, input().split()))
a -= 1
e = c * d // math.gcd(c, d)
print(b - b // c - b // d + b // e - (a - a // c - a // d + a // e))


(a, b, c, d) = map(int, input().split())
dcou = b // d - (a - 1) // d
ccou = b // c - (a - 1) // c
from math import gcd
dc = d * c // gcd(d, c)
dccou = b // dc - (a - 1) // dc
ans = b - a - dcou - ccou + dccou + 1
print(int(ans))


import math
(a, b, c, d) = map(int, input().split())
x = (a - 1) // c
y = b // c
z = (a - 1) // d
w = b // d
e = c * d // math.gcd(c, d)
p = (a - 1) // e
q = b // e
print(b - a + 1 - y + x - w + z + q - p)


from math import gcd
(a, b, c, d) = map(int, input().split())
e = c * d // gcd(c, d)
cntC = b // c - (a - 1) // c
cntD = b // d - (a - 1) // d
cntE = b // e - (a - 1) // e
print(b - a - (cntC + cntD - cntE) + 1)


import math
(a, b, c, d) = map(int, input().split())
(n, m, k) = (0, 0, 0)
if a % c == 0:
	n = b // c - a // c + 1
else:
	n = b // c - a // c
if a % d == 0:
	m = b // d - a // d + 1
else:
	m = b // d - a // d
e = c * d // math.gcd(c, d)
if a % e == 0:
	k = b // e - a // e + 1
else:
	k = b // e - a // e
k = n + m - k
print(b - a - k + 1)


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

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
e = c * d // gcd(c, d)
print(b - a - b // c + (a + c - 1) // c - b // d + (a + d - 1) // d + b // e - (a + e - 1) // e)


import math

def solve(a, c, d):
	x = a + 1
	x -= a // c + 1
	x -= a // d + 1
	x += a // (c * d // math.gcd(c, d)) + 1
	return x
(A, B, C, D) = list(map(int, input().split()))
print(solve(B, C, D) - solve(A - 1, C, D))


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
(A, B, C, D) = map(int, input().split())
c_multiples = B // C - (A - 1) // C
d_multiples = B // D - (A - 1) // D
lcm_multiples = B // lcm(C, D) - (A - 1) // lcm(C, D)
print(B - A + 1 - c_multiples - d_multiples + lcm_multiples)


import math
(A, B, C, D) = map(int, input().split(' '))
CD_least_common = C * D // math.gcd(C, D)
except_rst = B // C - (A - 1) // C + B // D - (A - 1) // D - (B // CD_least_common - (A - 1) // CD_least_common)
rst = B - (A - 1) - except_rst
print(rst)


from functools import reduce
from math import gcd

def lcm(n, c, d):
	g = gcd(c, d)
	l = c // g * d
	return n - n // c - n // d + n // l
(a, b, c, d) = map(int, input().split())
print(lcm(b, c, d) - lcm(a - 1, c, d))


import sys

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

def lcm(a, b):
	return a * b // gcd(a, b)
input = sys.stdin.readline
(a, b, c, d) = list(map(int, input().split()))
div_ac = (a - 1) // c
div_bc = b // c
div_ad = (a - 1) // d
div_bd = b // d
lcm_cd = lcm(c, d)
div_acd = (a - 1) // lcm_cd
div_bcd = b // lcm_cd
a_1_result = div_ac + div_ad - div_acd
b_result = div_bc + div_bd - div_bcd
print(b + 1 - a - (b_result - a_1_result))


import math
(a, b, c, d) = map(int, input().split())
n = b - a + 1

def lcm(x, y):
	return x * y // math.gcd(x, y)
x = lcm(c, d)
cc = b // c - (a - 1) // c
dc = b // d - (a - 1) // d
xc = b // x - (a - 1) // x
print(n - cc - dc + xc)


from math import gcd

def count(x, c, d):
	lcm = c // gcd(c, d) * d
	return x - x // c - x // d + x // lcm
(a, b, c, d) = list(map(int, input().split()))
print(count(b, c, d) - count(a - 1, c, d))


(A, B, C, D) = map(int, input().split())
A -= 1

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
lCD = C * D // gcd(C, D)
print(B - B // C - B // D + B // lCD - (A - A // C - A // D + A // lCD))


(a, b, c, d) = map(int, input().split())
(x, y) = (c, d)
while y != 0:
	(x, y) = (y, x % y)
lcm = c * d // x
c_upper = b // c
c_lower = -(-a // c)
d_upper = b // d
d_lower = -(-a // d)
lcm_upper = b // lcm
lcm_lower = -(-a // lcm)
print(b - a + 1 - (c_upper - c_lower + 1) - (d_upper - d_lower + 1) + (lcm_upper - lcm_lower + 1))


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

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
aa = b // c - a // c
bb = b // d - a // d
cc = b // lcm(c, d) - a // lcm(c, d)
print(b - a - (aa + bb - cc))


import math
(a, b, c, d) = map(int, input().split())
e = c * d // math.gcd(c, d)
if a % c == 0:
	p = b // c - a // c + 1
else:
	p = b // c - a // c
if a % d == 0:
	q = b // d - a // d + 1
else:
	q = b // d - a // d
if a % e == 0:
	r = b // e - a // e + 1
else:
	r = b // e - a // e
print(b - a + 1 - (p + q - r))


import math
(a, b, c, d) = map(int, input().split())
x = c * d // math.gcd(c, d)
ans = b - b // c - b // d + b // x - (a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // x)
print(ans)


import math

def lcm(x, y):
	return x * y // math.gcd(x, y)

def main():
	(a, b, c, d) = list(map(int, input().split()))
	a -= 1
	cd = lcm(c, d)
	ans = b - a - (b // c - a // c) - (b // d - a // d) + (b // cd - a // cd)
	print(ans)

def __starting_point():
	main()
__starting_point()


import math

def lcm(a, b):
	return a * b // math.gcd(a, b)
(a, b, c, d) = map(int, input().split())
l = lcm(c, d)
ans = b - a + 1 - (b // c + b // d - b // l - ((a - 1) // c + (a - 1) // d - (a - 1) // l))
print(ans)


(a, b, c, d) = map(int, input().split())
from math import gcd
ans = 0

def main(n):
	e = n // c + n // d - n // (c * d // gcd(c, d))
	return n - e
print(main(b) - main(a - 1))


import math
(A, B, C, D) = map(int, input().split())
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
lcm = C * D // math.gcd(C, D)
cd = B // lcm - (A - 1) // lcm
x = c + d - cd
print(B - A + 1 - x)


from math import gcd
(A, B, C, D) = map(int, input().split())
E = C * D // gcd(C, D)
ans = B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - B // E + (A - 1) // E)
print(ans)


import math

def cnt(a: int, k: int):
	return a // k

def num(a, c, d):
	m_a_c = cnt(a, c)
	m_a_d = cnt(a, d)
	m_a_cd = cnt(a, c * d // math.gcd(c, d))
	return a - m_a_c - m_a_d + m_a_cd
(a, b, c, d) = list(map(int, input().split()))
print(num(b, c, d) - num(a - 1, c, d))


(A, B, C, D) = map(int, input().split())

def gcd(x, y):
	if x == 0:
		return y
	if y == 0:
		return x
	if x >= y:
		return gcd(y, x % y)
	if x < y:
		return gcd(y % x, x)
l = C * D // gcd(C, D)
p = B // C - (A - 1) // C
q = B // D - (A - 1) // D
r = B // l - (A - 1) // l
s = p + q - r
print(B - A + 1 - s)


def lcm(a):
	from math import gcd
	x = a[0]
	for i in range(1, len(a)):
		x = x * a[i] // gcd(x, a[i])
	return x
(A, B, C, D) = map(int, input().split())
num = []
num.append(C)
num.append(D)
a = A - 1
x_B = B - B // C - B // D + B // lcm(num)
x_A = a - a // C - a // D + a // lcm(num)
ans = x_B - x_A
print(ans)


import math
(a, b, c, d) = map(int, input().split())
base = c * d // math.gcd(c, d)
c_num = b // c - (a - 1) // c
d_num = b // d - (a - 1) // d
base_num = b // base - (a - 1) // base
x = int(c_num + d_num - base_num)
print(b - a + 1 - x)


import math
(a, b, c, d) = map(int, input().split())
x = b // c - (a - 1) // c
y = b // d - (a - 1) // d
g = math.gcd(c, d)
l = c * d // g
z = b // l - (a - 1) // l
print(b - a + 1 - x - y + z)


import math
(A, B, C, D) = map(int, input().split(' '))
num_C_baisu = B // C - (A - 1) // C
num_D_baisu = B // D - (A - 1) // D
CD = int(C * D / math.gcd(C, D))
num_CD_baisu = B // CD - (A - 1) // CD
baisu_num = num_C_baisu + num_D_baisu - num_CD_baisu
print(B - A + 1 - baisu_num)


(A, B, C, D) = map(int, input().split())

def f(x):
	return B // x - (A - 1) // x
import math
E = int(C * D / math.gcd(C, D))
print(B - A + 1 - f(C) - f(D) + f(E))


import math
(A, B, C, D) = list(map(int, input().split()))
(divAC, modAC) = divmod(A, C)
(divBC, modBC) = divmod(B, C)
ans = 0
if modAC == 0:
	ans += divBC - divAC + 1
else:
	ans += divBC - divAC
(divAD, modAD) = divmod(A, D)
(divBD, modBD) = divmod(B, D)
if modAD == 0:
	ans += divBD - divAD + 1
else:
	ans += divBD - divAD
(divACD, modACD) = divmod(A, int(C * D / math.gcd(C, D)))
(divBCD, modBCD) = divmod(B, int(C * D / math.gcd(C, D)))
if modACD == 0:
	ans -= divBCD - divACD + 1
else:
	ans -= divBCD - divACD
print(B - A + 1 - ans)