program ccc
implicit none
integer(16) res
integer(16) a, b, c, d, x, y, z
integer(16) s
read*, a, b, c, d
x=max(c,d)
y=min(c,d)
res=1
z=c*d
 do while (res.ne.0)
 res=mod(x,y)
 if(res.ne.0) then
 y=res
 end if
 if(res.eq.0) then
 z=(c*d)/y
 end if
 end do
s=int(b/c)+int(b/d)-int((a-1)/c)-int((a-1)/d)-int(b/(z))+int((a-1)/(z))
s=(b-a+1)-s
print*, s, z
end program