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

    read*, a,b,c,d

    gcd = c*d/lcm(c,d)
    l = b-a
    print*, l-l/c-l/d+l/gcd

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