'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')[0].split(' ')
  const A = input[0]
  const B = input[1]
  const C = input[2]
  const D = input[3]
  let tmp1 = Math.floor(B / C)
  let hoge1 = Math.floor(A / C)
  let neko1 = tmp1 - hoge1

  let tmp2 = Math.floor(B / D)
  let hoge2 = Math.floor(A / D)
  let neko2 = tmp2 - hoge2
  if (A % D == 0) {
    neko2++
  }

  let y = lcm(C, D)

  let neko3 = 0
  if (y > 0) {
    let tmp3 = Math.floor(B / y)
    let hoge3 = Math.floor(A / y)
    neko3 = tmp3 - hoge3
  }

  console.log((B - A + 1) - (neko1 + neko2 - neko3))
}

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

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