#n=int(input())

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

#l=list(map(int,input().split()))

#l=[list(map(int,input().split())) for i in range(n)]

import fractions

lcm=(c*d)//fractions.gcd(c,d)#最小公倍数



brng=b-(b//c+b//d)+b//lcm

arng=(a-1)-((a-1)//c+(a-1)//d)+(a-1)//lcm

ans=brng-arng

print(ans)
#n=int(input())

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

#t=int(input())

#al=list(map(int,input().split()))

#l=[list(map(int,input().split())) for i in range(n)]

import math



lcm=(c//math.gcd(c,d))*d #最小公倍数



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

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

cdnum=b//lcm-(a-1)//lcm



ans=b-a+1-(cnum+dnum)+cdnum

print(ans)

# n=int(input())
a, b, c, d = list(map(int, input().split()))
# l=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
import fractions

lcm = (c * d) // fractions.gcd(c, d)  # 最小公倍数
brng = b - (b // c + b // d) + b // lcm
arng = (a - 1) - ((a - 1) // c + (a - 1) // d) + (a - 1) // lcm
ans = brng - arng
print(ans)

# n=int(input())
a, b, c, d = list(map(int, input().split()))
# t=int(input())
# al=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
import math

lcm = (c // math.gcd(c, d)) * d  # 最小公倍数
cnum = b // c - (a - 1) // c
dnum = b // d - (a - 1) // d
cdnum = b // lcm - (a - 1) // lcm
ans = b - a + 1 - (cnum + dnum) + cdnum
print(ans)

-# l=list(map(int,input().split())) +# t=int(input()) +# al=list(map(int,input().split())) -import fractions +import math -lcm = (c * d) // fractions.gcd(c, d)  # 最小公倍数 -brng = b - (b // c + b // d) + b // lcm -arng = (a - 1) - ((a - 1) // c + (a - 1) // d) + (a - 1) // lcm -ans = brng - arng +lcm = (c // math.gcd(c, d)) * d  # 最小公倍数 +cnum = b // c - (a - 1) // c +dnum = b // d - (a - 1) // d +cdnum = b // lcm - (a - 1) // lcm +ans = b - a + 1 - (cnum + dnum) + cdnum