program ABC
    integer(8) a, b, c, d, L
    read*, a, b, c, d
    a = a - 1
    L = c * d / GCD(c, d)
    print"(i0)", ((b - b / c - b / d + b / L) - (a - a / c - a / d + a / L))
contains
    !GCDを求めるよ！
    recursive integer(8) function GCD (a, b) result (res)
        implicit none
        integer(8) a, b
        if (b > 0) then
            res = GCD(b, mod(a, b))
        else 
            res = a
        end if
    end function
end program ABC
