program main
 implicit none
 integer*16 a,b,c,d,t1,t2,gcd,lcm,p,q,ans
 read(*,*) a,b,c,d
 t1 = c
 t2 = d
 do while( t2 /= 0 )
     gcd = t1
     t1 = t2
     t2 = mod(gcd, t2)
 end do
 gcd = abs(t1)
 lcm = c*d / gcd
 p = b / c + b / d - b / lcm
 q = (a-1) / c + (a-1) / d - (a-1) / lcm
 ans = b - (a-1) - (p - q)
 write(*,*) ans
end program main