# ABC131 C Anti-Division

from fractions import gcd

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

n = b-a+1

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



a_c = (a-1)//c

a_d = (a-1)//d

a_cd = (a-1)//cd



b_c = b//c

b_d = b//d

b_cd = b//cd



print((n- ((b_c-a_c)+(b_d-a_d)-((b_cd-a_cd)))))
from fractions import gcd

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

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



bc=b//c

bd=b//d

bcd=b//(cd)

b_cnt=b-(bc+bd-bcd)



ac=(a-1)//c

ad=(a-1)//d

acd=(a-1)//(cd)

a_cnt=a-1-(ac+ad-acd)



print((b_cnt-a_cnt))
# ABC131 C Anti-Division
from fractions import gcd

a, b, c, d = list(map(int, input().split()))
n = b - a + 1
cd = (c * d) // gcd(c, d)
a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // cd
b_c = b // c
b_d = b // d
b_cd = b // cd
print((n - ((b_c - a_c) + (b_d - a_d) - ((b_cd - a_cd)))))

from fractions import gcd

a, b, c, d = list(map(int, input().split()))
cd = (c * d) // gcd(c, d)
bc = b // c
bd = b // d
bcd = b // (cd)
b_cnt = b - (bc + bd - bcd)
ac = (a - 1) // c
ad = (a - 1) // d
acd = (a - 1) // (cd)
a_cnt = a - 1 - (ac + ad - acd)
print((b_cnt - a_cnt))

-# ABC131 C Anti-Division -n = b - a + 1 -a_c = (a - 1) // c -a_d = (a - 1) // d -a_cd = (a - 1) // cd -b_c = b // c -b_d = b // d -b_cd = b // cd -print((n - ((b_c - a_c) + (b_d - a_d) - ((b_cd - a_cd))))) +bc = b // c +bd = b // d +bcd = b // (cd) +b_cnt = b - (bc + bd - bcd) +ac = (a - 1) // c +ad = (a - 1) // d +acd = (a - 1) // (cd) +a_cnt = a - 1 - (ac + ad - acd) +print((b_cnt - a_cnt))