'use strict'

function gcd(a,b){
  if(b==0){return a;}
  return gcd(b,a%b);
}

function lcm(a, b){
  return a*b/gcd(a,b);
}

function main(input){
  const A = input.split(' ').map(x => parseInt(x))[0];
  const B = input.split(' ').map(x => parseInt(x))[1];
  const C = input.split(' ').map(x => parseInt(x))[2];
  const D = input.split(' ').map(x => parseInt(x))[3];
  const CD = lcm(C,D);

//  console.log([A,B,C,D]);

  const part_c = Math.ceil(B/C - (A-1)/C);
  const part_d = Math.ceil(B/D - (A-1)/D);
  const part_cd = Math.ceil(B/CD - (A-1)/CD);

  let result = (B-A+1) - (part_c + part_d - part_cd)
  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
