import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    // 入力値の読み込み
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  }
  
  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.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    // 入力値の読み込み
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  }
  
  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()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  } main {
    // 入力値の読み込み
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = sc.nextLong()-1; A sc.nextLong()-1 sc.nextLong() sc.nextLong sc 1 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 A_C = A / C; A_C A / C A C long A_D = A / D; A_D A / D A D long A_CD = A / lcm(C, D); A_CD A / lcm(C, D) A lcm(C, D) lcm C D long cntA = A_C + A_D - A_CD; cntA A_C + A_D - A_CD A_C + A_D A_C A_D A_CD long B_C = B / C; B_C B / C B C long B_D = B / D; B_D B / D B D long B_CD = B / lcm(C, D); B_CD B / lcm(C, D) B lcm(C, D) lcm C D long cntB = B_C + B_D - B_CD; cntB B_C + B_D - B_CD B_C + B_D B_C B_D B_CD System.out.println(B - A - (cntB - cntA)) System.out.println System.out System System.out B - A - (cntB - cntA) B - A - (cntB - cntA) B A (cntB - cntA) cntB cntA 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()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  }
  
  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()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  }
  
  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.Scanner;

public class Main{
  public static void main(String[] args){
    // 入力値の読み込み
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  }
  
  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);
  }
  
}