"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');
let input = '';

process.stdin.on('data', function(chunk) {
  input += chunk;
}).on('end', function() {
  input = input.trim().split(" ").map(v => parseInt(v));
  const A = input[0];
  const B = input[1];
  const C = input[2];
  const D = input[3];
  let result = B - A + 1 - (Math.floor(B / C) + Math.floor(B / D) - Math.floor(B / lcm(C, D)) - (Math.floor((A - 1) / C) + Math.floor((A - 1) / D) - Math.floor((A - 1) / lcm(C, D))));
  console.log(result);
});

function lcm(a,b) {
  const g = (n, m) => m ? g(m, n % m) : n;
  return a * b / g(a, b)
}
