"use strict";
function Main(input) {
  const args = input.split(' ').map(m => parseInt(m));
  const A = args.shift();
  const B = args.shift();
  const C = args.shift();
  const D = args.shift();

  let rtn = B - A + 1;
  let lower = C;
  let higher = D;
  if (C > D) {
    lower = C;
    higher = D;
  }
  //値の小さいもので割り切れる数
  rtn -= Math.trunc(B / lower) - Math.trunc((A - 1) / lower);
  //値の大きいもので割り切れる数
  rtn -= Math.trunc(B / higher) - Math.trunc((A - 1) / higher);

  // 最小公倍数で加算
  let lcm;
  if (higher % lower === 0) {
    lcm = lower;
  } else {
    for (let i = 1; i <= lower; i++) {
      lcm = higher * i;
      if (lcm % lower === 0) {
        break;
      }
    }
  }
  rtn += Math.trunc(B / lcm) - Math.trunc(A / lcm);

  console.log(rtn);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
