import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  }

  private static long leastCommonMultiple(long a, long b) {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  }
}
 import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  }

  private static long leastCommonMultiple(long a, long b) {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  }
} Main public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  } main {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long A = scan.nextLong(); A scan.nextLong() scan.nextLong scan long B = scan.nextLong(); B scan.nextLong() scan.nextLong scan long C = scan.nextLong(); C scan.nextLong() scan.nextLong scan long D = scan.nextLong(); D scan.nextLong() scan.nextLong scan long CD = leastCommonMultiple(C, D); CD leastCommonMultiple(C, D) leastCommonMultiple C D long cStart; cStart long dStart; dStart long cdStart; cdStart if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    } A % C == 0 A % C A C 0 {
      cStart = A / C;
    } cStart = A / C cStart A / C A C {
      cStart = A / C + 1;
    } cStart = A / C + 1 cStart A / C + 1 A / C A C 1 if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    } A % D == 0 A % D A D 0 {
      dStart = A / D;
    } dStart = A / D dStart A / D A D {
      dStart = A / D + 1;
    } dStart = A / D + 1 dStart A / D + 1 A / D A D 1 if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    } A % CD == 0 A % CD A CD 0 {
      cdStart = A / CD;
    } cdStart = A / CD cdStart A / CD A CD {
      cdStart = A / CD + 1;
    } cdStart = A / CD + 1 cdStart A / CD + 1 A / CD A CD 1 long cEnd = B / C; cEnd B / C B C long dEnd = B / D; dEnd B / D B D long cdEnd = B / CD; cdEnd B / CD B CD long cn = cEnd - cStart + 1; cn cEnd - cStart + 1 cEnd - cStart cEnd cStart 1 long dn = dEnd - dStart + 1; dn dEnd - dStart + 1 dEnd - dStart dEnd dStart 1 long cdn = cdEnd - cdStart + 1; cdn cdEnd - cdStart + 1 cdEnd - cdStart cdEnd cdStart 1 long result = B - A + 1 - cn - dn + cdn; result B - A + 1 - cn - dn + cdn B - A + 1 - cn - dn B - A + 1 - cn - dn B - A + 1 B - A B A 1 cn dn cdn System.out.println(result) System.out.println System.out System System.out result String[] args args private static long leastCommonMultiple(long a, long b) {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  } leastCommonMultiple {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  } long temp; temp long c = a; c a c *= b c b while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    } (temp = a % b) != 0 (temp = a % b) temp a % b a b 0 {
      a = b;
      b = temp;
    } a = b a b b = temp b temp return c / b; c / b c b long a a long b b public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  }

  private static long leastCommonMultiple(long a, long b) {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  }

  private static long leastCommonMultiple(long a, long b) {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  }

  private static long leastCommonMultiple(long a, long b) {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  }
}

