import fractions

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

count=0

e=(c*d)//fractions.gcd(c,d)

D=[c,d,e]

f=[]



for i in D:

  f.append((b//i)-((a-1)//i))

print((b-a+1-f[0]-f[1]+f[2]))
import fractions

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

e=(c*d)//fractions.gcd(c,d)

a=a-1

n1=a-(a//c + a//d - a//e)

n2=b-(b//c + b//d - b//e)



print((n2-n1))
import fractions

a, b, c, d = list(map(int, input().split()))
count = 0
e = (c * d) // fractions.gcd(c, d)
D = [c, d, e]
f = []
for i in D:
    f.append((b // i) - ((a - 1) // i))
print((b - a + 1 - f[0] - f[1] + f[2]))

import fractions

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

-count = 0 -D = [c, d, e] -f = [] -for i in D: -    f.append((b // i) - ((a - 1) // i)) -print((b - a + 1 - f[0] - f[1] + f[2])) +a = a - 1 +n1 = a - (a // c + a // d - a // e) +n2 = b - (b // c + b // d - b // e) +print((n2 - n1))