program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: a,b,c,d,cd

    read*, a,b,c,d
    cd = lcd(c,d)
    print'(i0)', (b-a+1) - (b/c-(a-1)/c) - (b/d-(a-1)/d) + (b/cd-(a-1)/cd)


contains
function lcd(x,y) result(ret)
    integer(int64):: x,y,ret
    ret = x*y/gcd(x,y)
end function

recursive function gcd(x,y) result(ret)
    integer(int64):: x,y,ret

    if (mod(x,y) == 0) then
        ret = y
        return
    end if

    ret = gcd(y,mod(x,y))
end function
end program name