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 e = (c * d) / gcd(c, d);
    long ans = 0;
    if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    }
    System.out.println(ans);
  }

  public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
} 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 e = (c * d) / gcd(c, d);
    long ans = 0;
    if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    }
    System.out.println(ans);
  }

  public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
} 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 e = (c * d) / gcd(c, d);
    long ans = 0;
    if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    }
    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 e = (c * d) / gcd(c, d);
    long ans = 0;
    if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    }
    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 e = (c * d) / gcd(c, d); e (c * d) / gcd(c, d) (c * d) c d gcd(c, d) gcd c d long ans = 0; ans 0 if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    } a == 1 a 1 {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } long t = (b / c); t (b / c) b c t += (b / d) t (b / d) b d t -= (b / e) t (b / e) b e ans = (b - t) ans (b - t) b t {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    } long t1 = (b / c); t1 (b / c) b c t1 += (b / d) t1 (b / d) b d t1 -= (b / e) t1 (b / e) b e long t2 = ((a - 1) / c); t2 ((a - 1) / c) (a - 1) a 1 c t2 += ((a - 1) / d) t2 ((a - 1) / d) (a - 1) a 1 d t2 -= ((a - 1) / e) t2 ((a - 1) / e) (a - 1) a 1 e ans = (b - t1 + t2 - a + 1) ans (b - t1 + t2 - a + 1) b - t1 + t2 - a b - t1 + t2 b - t1 b t1 t2 a 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  } gcd {
    if(y == 0) return x;
    return gcd(y, (x % y));
  } if(y == 0) return x; y == 0 y 0 return x; x return gcd(y, (x % y)); gcd(y, (x % y)) gcd y (x % y) x y long x x long y y 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 e = (c * d) / gcd(c, d);
    long ans = 0;
    if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    }
    System.out.println(ans);
  }

  public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
} 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 e = (c * d) / gcd(c, d);
    long ans = 0;
    if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    }
    System.out.println(ans);
  }

  public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
} 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 e = (c * d) / gcd(c, d);
    long ans = 0;
    if(a == 1) {
      long t = (b / c);
      t += (b / d);
      t -= (b / e);
      ans = (b - t);
    } else {
      long t1 = (b / c);
      t1 += (b / d);
      t1 -= (b / e);
      long t2 = ((a - 1) / c);
      t2 += ((a - 1) / d);
      t2 -= ((a - 1) / e);      
      ans = (b - t1 + t2 - a + 1);      
    }
    System.out.println(ans);
  }

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