integer(8) A,B,C,D,E
integer(8) ans
read*,A,B,C,D
E=C*D/gcd(C,D)
ans=B-A+1

ans=ans-(B-A+1)/C-(B-A+1)/D +(B-A+1)/E
if(mod(B,C)<mod(A,C))ans=ans-1
if(mod(B,D)<mod(A,D))ans=ans-1
if(mod(B,E)<mod(A,E))ans=ans+1

if(mod(A,C)==0)ans=ans-1
if(mod(A,D)==0)ans=ans-1
if(mod(A,E)==0)ans=ans+1

print"(i0)",ans

contains

pure function gcd(a,b)
integer(8),intent(in)::a,b
integer(8) gcd
integer(8) s,t
s=a
gcd=b

t=mod(s,gcd)
do while(t/=0)
  s=gcd
  gcd=t
  t=mod(s,gcd)
end do
end function gcd
end