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

minus=B/C-(A-1)/C + B/D-(A-1)/D - B/E+(A-1)/E

print"(i0)",ans-minus

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