'use strict';
function main(input) {
  const args = input.split(' '),
        A = parseInt(args[0]),
        B = parseInt(args[1]),
        C = parseInt(args[2]),
        D = parseInt(args[3]);
  
  function gcd(x, y) {
    if (x > y) {
      if (y === 0) {
        return x;
      } else {
        return gcd(y, x%y);
      }
    } else {
      if (x === 0) {
        return y;
      } else {
        return gcd(x, y%x);
      }
    }
  }
  
  function lcm(x, y) {
    return x * y / gcd(x, y);
  }
  
  const add = Math.floor(B/C) + Math.floor(B/D) - Math.floor(B/lcm(C, D)),
        subtract = Math.floor((A-1)/C) + Math.floor((A-1)/D) - Math.floor((A-1)/lcm(C, D)),
        number = add - subtract,
        ans = (B - A + 1) - number;
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));