import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  }
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

  private static long lcm(long m, long n) {
      return m * n / gcd(m, n);
  }

} import java.util.*; util.* java public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  }
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

  private static long lcm(long m, long n) {
      return m * n / gcd(m, n);
  }

} Main public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong(); a sc.nextLong() sc.nextLong sc long b = sc.nextLong(); b sc.nextLong() sc.nextLong sc long c = sc.nextLong(); c sc.nextLong() sc.nextLong sc long d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long min = Math.min(b / c, b / d) + 1; min Math.min(b / c, b / d) + 1 Math.min(b / c, b / d) Math.min Math b / c b c b / d b d 1 long m = lcm(c ,d); m lcm(c ,d) lcm c d long x = b - a + 1; x b - a + 1 b - a b a 1 long y = (b / c) - (a - 1) / c; y (b / c) - (a - 1) / c (b / c) b c (a - 1) / c (a - 1) a 1 c long z = (b / d) - (a - 1) / d; z (b / d) - (a - 1) / d (b / d) b d (a - 1) / d (a - 1) a 1 d long w = (b / m) - (a - 1) / m; w (b / m) - (a - 1) / m (b / m) b m (a - 1) / m (a - 1) a 1 m long ans = x - y - z + w; ans x - y - z + w x - y - z x - y - z x y z w System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  } gcd {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n private static long lcm(long m, long n) {
      return m * n / gcd(m, n);
  } lcm {
      return m * n / gcd(m, n);
  } return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  }
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

  private static long lcm(long m, long n) {
      return m * n / gcd(m, n);
  }

} public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  }
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

  private static long lcm(long m, long n) {
      return m * n / gcd(m, n);
  }

} Main
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  }
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

  private static long lcm(long m, long n) {
      return m * n / gcd(m, n);
  }

}
