function gcd(a,b)
    if b~=0 then
        return gcd(b,a%b)
    else
        return a
    end
end
a,b,c,d=io.read("*n","*n","*n","*n")
x=(b//c+b//d-b//((c*d)//gcd(c,d)))-((a-1)//c+(a-1)//d-(a-1)//((c*d)//gcd(c,d)))
print(b-a+1-x)