import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long ua = a - 1;
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long lcm = lcm(c, d);

    long count = 0;
    
    long cCMsCount = b / c - ua / c;
    long dCMsCount = b / d - ua / d;
    long lcmCMsCount = b / lcm - ua / lcm;
    
    long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount;
    count = b - a + 1 - wholeCMsCount;
    
//    System.out.println(cCMsCount);
//    System.out.println(dCMsCount);
//    System.out.println(lcmCMsCount);
//    System.out.println(wholeCMsCount);
    System.out.println(count);
  }
  
  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 ua = a - 1;
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long lcm = lcm(c, d);

    long count = 0;
    
    long cCMsCount = b / c - ua / c;
    long dCMsCount = b / d - ua / d;
    long lcmCMsCount = b / lcm - ua / lcm;
    
    long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount;
    count = b - a + 1 - wholeCMsCount;
    
//    System.out.println(cCMsCount);
//    System.out.println(dCMsCount);
//    System.out.println(lcmCMsCount);
//    System.out.println(wholeCMsCount);
    System.out.println(count);
  }
  
  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 ua = a - 1;
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long lcm = lcm(c, d);

    long count = 0;
    
    long cCMsCount = b / c - ua / c;
    long dCMsCount = b / d - ua / d;
    long lcmCMsCount = b / lcm - ua / lcm;
    
    long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount;
    count = b - a + 1 - wholeCMsCount;
    
//    System.out.println(cCMsCount);
//    System.out.println(dCMsCount);
//    System.out.println(lcmCMsCount);
//    System.out.println(wholeCMsCount);
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long ua = a - 1;
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long lcm = lcm(c, d);

    long count = 0;
    
    long cCMsCount = b / c - ua / c;
    long dCMsCount = b / d - ua / d;
    long lcmCMsCount = b / lcm - ua / lcm;
    
    long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount;
    count = b - a + 1 - wholeCMsCount;
    
//    System.out.println(cCMsCount);
//    System.out.println(dCMsCount);
//    System.out.println(lcmCMsCount);
//    System.out.println(wholeCMsCount);
    System.out.println(count);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong(); a sc.nextLong() sc.nextLong sc long ua = a - 1; ua a - 1 a 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 lcm = lcm(c, d); lcm lcm(c, d) lcm c d long count = 0; count 0 long cCMsCount = b / c - ua / c; cCMsCount b / c - ua / c b / c b c ua / c ua c long dCMsCount = b / d - ua / d; dCMsCount b / d - ua / d b / d b d ua / d ua d long lcmCMsCount = b / lcm - ua / lcm; lcmCMsCount b / lcm - ua / lcm b / lcm b lcm ua / lcm ua lcm long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount; wholeCMsCount cCMsCount + dCMsCount - lcmCMsCount cCMsCount + dCMsCount cCMsCount dCMsCount lcmCMsCount count = b - a + 1 - wholeCMsCount count b - a + 1 - wholeCMsCount b - a + 1 b - a b a 1 wholeCMsCount System.out.println(count) System.out.println System.out System System.out count 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 ua = a - 1;
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long lcm = lcm(c, d);

    long count = 0;
    
    long cCMsCount = b / c - ua / c;
    long dCMsCount = b / d - ua / d;
    long lcmCMsCount = b / lcm - ua / lcm;
    
    long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount;
    count = b - a + 1 - wholeCMsCount;
    
//    System.out.println(cCMsCount);
//    System.out.println(dCMsCount);
//    System.out.println(lcmCMsCount);
//    System.out.println(wholeCMsCount);
    System.out.println(count);
  }
  
  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 ua = a - 1;
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long lcm = lcm(c, d);

    long count = 0;
    
    long cCMsCount = b / c - ua / c;
    long dCMsCount = b / d - ua / d;
    long lcmCMsCount = b / lcm - ua / lcm;
    
    long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount;
    count = b - a + 1 - wholeCMsCount;
    
//    System.out.println(cCMsCount);
//    System.out.println(dCMsCount);
//    System.out.println(lcmCMsCount);
//    System.out.println(wholeCMsCount);
    System.out.println(count);
  }
  
  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 ua = a - 1;
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long lcm = lcm(c, d);

    long count = 0;
    
    long cCMsCount = b / c - ua / c;
    long dCMsCount = b / d - ua / d;
    long lcmCMsCount = b / lcm - ua / lcm;
    
    long wholeCMsCount = cCMsCount + dCMsCount - lcmCMsCount;
    count = b - a + 1 - wholeCMsCount;
    
//    System.out.println(cCMsCount);
//    System.out.println(dCMsCount);
//    System.out.println(lcmCMsCount);
//    System.out.println(wholeCMsCount);
    System.out.println(count);
  }
  
  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);
  }  
  
}
