import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  }

  public static long calc(long a, long b, long c) {
    return b / c - (a - 1) / c;
  }

  public static long gcd(long x, long y) {
    return y == 0 ? x : gcd(y, x % y);
  }

  public static long lcm(long x, long y) {
    return x * (y / gcd(x, y));
  }
} import java.util.*; util.* java import java.util.stream.*; stream.* java.util public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  }

  public static long calc(long a, long b, long c) {
    return b / c - (a - 1) / c;
  }

  public static long gcd(long x, long y) {
    return y == 0 ? x : gcd(y, x % y);
  }

  public static long lcm(long x, long y) {
    return x * (y / gcd(x, y));
  }
} Main public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  } main {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) long A = in.nextLong() A in.nextLong() in.nextLong in B = in.nextLong() B in.nextLong() in.nextLong in C = in.nextLong() C in.nextLong() in.nextLong in D = in.nextLong(); D in.nextLong() in.nextLong in System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D))) System.out.println System.out System System.out (B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)) (B - A + 1) - calc(A, B, C) - calc(A, B, D) (B - A + 1) - calc(A, B, C) - calc(A, B, D) (B - A + 1) B - A B A 1 calc(A, B, C) calc A B C calc(A, B, D) calc A B D calc(A, B, lcm(C, D)) calc A B lcm(C, D) lcm C D String[] args args public static long calc(long a, long b, long c) {
    return b / c - (a - 1) / c;
  } calc {
    return b / c - (a - 1) / c;
  } return b / c - (a - 1) / c; b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long a a long b b long c c public static long gcd(long x, long y) {
    return y == 0 ? x : gcd(y, x % y);
  } gcd {
    return y == 0 ? x : gcd(y, x % y);
  } return y == 0 ? x : gcd(y, x % y); y == 0 ? x : gcd(y, x % y) y == 0 y 0 x gcd(y, x % y) gcd y x % y x y long x x long y y public static long lcm(long x, long y) {
    return x * (y / gcd(x, y));
  } lcm {
    return x * (y / gcd(x, y));
  } return x * (y / gcd(x, y)); x * (y / gcd(x, y)) x (y / gcd(x, y)) y gcd(x, y) gcd x y long x x long y y public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  }

  public static long calc(long a, long b, long c) {
    return b / c - (a - 1) / c;
  }

  public static long gcd(long x, long y) {
    return y == 0 ? x : gcd(y, x % y);
  }

  public static long lcm(long x, long y) {
    return x * (y / gcd(x, y));
  }
} public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  }

  public static long calc(long a, long b, long c) {
    return b / c - (a - 1) / c;
  }

  public static long gcd(long x, long y) {
    return y == 0 ? x : gcd(y, x % y);
  }

  public static long lcm(long x, long y) {
    return x * (y / gcd(x, y));
  }
} Main
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  }

  public static long calc(long a, long b, long c) {
    return b / c - (a - 1) / c;
  }

  public static long gcd(long x, long y) {
    return y == 0 ? x : gcd(y, x % y);
  }

  public static long lcm(long x, long y) {
    return x * (y / gcd(x, y));
  }
}