const input = require("fs").readFileSync("/dev/stdin", "utf8");

const data = input.split('\n')[0].split(' ');
const A = +data[0];
const B = +data[1];
const C = +data[2];
const D = +data[3];

const y = (n, m) => m ? y(m, n % m) : n;
const sky = (n, m) => {
  return n * m / y(n, m);
};

const CD = sky(C, D);

const banA = Math.floor((A - 1) / C) + Math.floor((A - 1) / D) - Math.floor((A - 1) / CD);
const a = (A - 1) - banA;

const banB = Math.floor(B / C) + Math.floor(B / D) - Math.floor(B / CD);
const b = (B - banB);

console.log(b - a);
