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 bmade = B/C+B/D-B/(lcm(C,D));
      long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D));
      

 
      System.out.println(B-A-(bmade-amade)+1);
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  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);
}
} 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 bmade = B/C+B/D-B/(lcm(C,D));
      long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D));
      

 
      System.out.println(B-A-(bmade-amade)+1);
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  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);
}
} 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 bmade = B/C+B/D-B/(lcm(C,D));
      long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D));
      

 
      System.out.println(B-A-(bmade-amade)+1);
    } main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long A = sc.nextLong();
      long B = sc.nextLong();
      long C = sc.nextLong();
      long D = sc.nextLong();
      long bmade = B/C+B/D-B/(lcm(C,D));
      long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D));
      

 
      System.out.println(B-A-(bmade-amade)+1);
    } 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 bmade = B/C+B/D-B/(lcm(C,D)); bmade B/C+B/D-B/(lcm(C,D)) B/C+B/D B/C B C B/D B D B/(lcm(C,D)) B (lcm(C,D)) lcm C D long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D)); amade (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D)) (A-1)/C+(A-1)/D (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/(lcm(C,D)) (A-1) A 1 (lcm(C,D)) lcm C D System.out.println(B-A-(bmade-amade)+1) System.out.println System.out System System.out B-A-(bmade-amade)+1 B-A-(bmade-amade) B-A-(bmade-amade) B A (bmade-amade) bmade amade 1 String[] args args 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 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 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 bmade = B/C+B/D-B/(lcm(C,D));
      long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D));
      

 
      System.out.println(B-A-(bmade-amade)+1);
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  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);
}
} 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 bmade = B/C+B/D-B/(lcm(C,D));
      long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D));
      

 
      System.out.println(B-A-(bmade-amade)+1);
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  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);
}
} 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 bmade = B/C+B/D-B/(lcm(C,D));
      long amade = (A-1)/C+(A-1)/D-(A-1)/(lcm(C,D));
      

 
      System.out.println(B-A-(bmade-amade)+1);
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  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);
}
}