import fractions

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



ac=(a-1)//c

bc=b//c

ad=(a-1)//d

bd=b//d





f=fractions.gcd(c,d)

f=c*d//f



af=(a-1)//f

bf=b//f







print(((b-a+1)-(bc-ac)-(bd-ad)+(bf-af)))
import fractions

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

a=a-1



ac=a//c

ad=a//d

bc=b//c

bd=b//d



f=fractions.gcd(c,d)

f=c*d//f



acd=a//f

bcd=b//f



print(((b-a)-(bc-ac)-(bd-ad)+(bcd-acd)))

import fractions

a, b, c, d = list(map(int, input().split()))
ac = (a - 1) // c
bc = b // c
ad = (a - 1) // d
bd = b // d
f = fractions.gcd(c, d)
f = c * d // f
af = (a - 1) // f
bf = b // f
print(((b - a + 1) - (bc - ac) - (bd - ad) + (bf - af)))

import fractions

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

-ac = (a - 1) // c +a = a - 1 +ac = a // c +ad = a // d -ad = (a - 1) // d -af = (a - 1) // f -bf = b // f -print(((b - a + 1) - (bc - ac) - (bd - ad) + (bf - af))) +acd = a // f +bcd = b // f +print(((b - a) - (bc - ac) - (bd - ad) + (bcd - acd)))