program kadai
implicit none
integer(8)  ::  a,b
integer(8) ::  c,d
integer(8)  ::  sa,sb,i,g
integer(8)  ::  aac,aad,bbc,bbd,alpha1,alpha2
integer(8)  ::  unta,untb,ans

read(*,*) a,b,c,d
a=a-1
aac=a/c
aad=a/d
bbc=b/c
bbd=b/d

sa=dble(c*d)
g=gcd(c,d)
alpha1=a/(sa/g)
alpha2=b/(sa/g)

untb=b-(bbc+bbd-alpha2)
unta=a-(aac+aad-alpha1)
ans=untb-unta

write(*,*) ans

stop
contains
integer function gcd(a,b)
    implicit none
    integer(8),intent(in)  ::  a,b
    integer(8)  ::  l,m,n
    m=a
    n=b
    do
        l=mod(m,n)
        if (l==0) then
            exit
        end if
        m=n
        n=l
    end do
    gcd=n
    return
end function gcd




end program kadai
