import fractions

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

base=b-a+1

n_c=b//c-(a+c-1)//c+1

n_d=b//d-(a+d-1)//d+1

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

n_cd=b//cd-(a+cd-1)//cd+1

print((base-n_c-n_d+n_cd))

import fractions

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

nc=b//c-(a+c-1)//c+1

nd=b//d-(a+d-1)//d+1

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

ncd=b//cd-(a+cd-1)//cd+1

print((b-a+1-(nc+nd-ncd)))



# math.ceil(a/b)->(a+b-1)//b
import fractions

a, b, c, d = list(map(int, input().split()))
base = b - a + 1
n_c = b // c - (a + c - 1) // c + 1
n_d = b // d - (a + d - 1) // d + 1
cd = c * d // fractions.gcd(c, d)
n_cd = b // cd - (a + cd - 1) // cd + 1
print((base - n_c - n_d + n_cd))

import fractions

a, b, c, d = list(map(int, input().split()))
nc = b // c - (a + c - 1) // c + 1
nd = b // d - (a + d - 1) // d + 1
cd = c * d // fractions.gcd(c, d)
ncd = b // cd - (a + cd - 1) // cd + 1
print((b - a + 1 - (nc + nd - ncd)))
# math.ceil(a/b)->(a+b-1)//b

-base = b - a + 1 -n_c = b // c - (a + c - 1) // c + 1 -n_d = b // d - (a + d - 1) // d + 1 +nc = b // c - (a + c - 1) // c + 1 +nd = b // d - (a + d - 1) // d + 1 -n_cd = b // cd - (a + cd - 1) // cd + 1 -print((base - n_c - n_d + n_cd)) +ncd = b // cd - (a + cd - 1) // cd + 1 +print((b - a + 1 - (nc + nd - ncd))) +# math.ceil(a/b)->(a+b-1)//b