require 'pp'
require 'set'
require 'prime'

a,b,c,d = gets.chomp!.split(" ").map(&:to_i)

# cとdの最小公倍数
c_p = Prime.prime_division(c).to_h
d_p = Prime.prime_division(d).to_h

koubai = {1 => 1}
c_p.each do |v, c|
    if d_p[v] != nil
        s = [c, d_p[v]].max
        koubai[v] = s 
    else
        koubai[v] = c
    end

    d_p.delete(v)
end

koubai = koubai.merge(d_p)
min_koubai = 1
koubai.each do |k, v|
    min_koubai *= (k ** v)
end

# c の倍数
x = a / c
y = b / c
c_c = y - x + (a % c == 0 ? 1 : 0)

# d の倍数
x = a / d
y = b / d
d_c = y - x + (a % d == 0 ? 1 : 0)

# c*d の倍数の倍数
x = a / min_koubai
y = b / min_koubai
min_c = y - x + (a % min_koubai == 0 ? 1 : 0)

sum = b - a + 1
#puts sum
#puts c_c
#puts d_c
#puts min_c
puts sum - c_c - d_c + min_c
