/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
4 9 2 3
---+/
/+---test
10 40 6 8
---+/
/+---test
314159265358979323 846264338327950288 419716939 937510582
---+/

void main(string[] args) {
  long A, B, C, D;
  readf(" %d %d %d %d ", &A, &B, &C, &D);

  const E = C*D / gcd(C, D);

  long ans = B/C - A/C + (A%C == 0);
  ans     += B/D - A/D + (A%D == 0);
  ans     -= B/E - A/E + (A%E == 0);
  (B-A-ans+1).writeln;
}
