main = do
  [a,b,c,d] <- map read.words<$>getLine :: IO [Integer]
  print $ solve a b c d

solve a b c d = cs + ds - cds
  where
  [cs, ds, cds] = map f [c, d, lcm c d]
  f n = (b-a+1) - ( b`div`n - (a-1)`div`n)