'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
let Nums = input.split(" ");
let A = Nums[0]*1;
let B = Nums[1]*1;
let C = Nums[2]*1;
let D = Nums[3]*1;
let ans = 0;
let AdiffB = B - A;
let gcd = (a,b) => {return a % b == 0 ? b : gcd(b , a % b)};
let lcm = (a,b) => {return a * b / gcd(a,b)};
console.log(
  AdiffB
  - (Math.floor(AdiffB/C))
  - (Math.floor(AdiffB/D))
  + Math.floor(AdiffB/lcm(C,D))
);