program anti_division
    implicit none
    integer(8):: a,b,c,d,gcd,ans_a, ans_b

    read*, a,b,c,d

    gcd = c*d/lcm(c,d)

    ans_a = (a-1) - (a-1)/c - (a-1)/d +(a-1)/gcd
    ans_b = b - b/c - b/d + b/gcd

    print*, ans_b - ans_a

contains
recursive function lcm(a,b) result(ret)
    integer(8),intent(in):: a,b
    integer(8):: ret

    if (mod(a,b) == 0) then
        ret = b
        return
    end if
    ret = lcm(b,mod(a,b))
end function
end program anti_division