import java.util.*;

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 E = lcm(C,D);
    
    long big = B - B/C - B/D + B/E;
    long small = A -A/C -A/D + A/E;
    System.out.println(big-small);
    
  }
  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 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 E = lcm(C,D);
    
    long big = B - B/C - B/D + B/E;
    long small = A -A/C -A/D + A/E;
    System.out.println(big-small);
    
  }
  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 E = lcm(C,D);
    
    long big = B - B/C - B/D + B/E;
    long small = A -A/C -A/D + A/E;
    System.out.println(big-small);
    
  } 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 E = lcm(C,D);
    
    long big = B - B/C - B/D + B/E;
    long small = A -A/C -A/D + A/E;
    System.out.println(big-small);
    
  } 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 E = lcm(C,D); E lcm(C,D) lcm C D long big = B - B/C - B/D + B/E; big B - B/C - B/D + B/E B - B/C - B/D B - B/C - B/D B B/C B C B/D B D B/E B E long small = A -A/C -A/D + A/E; small A -A/C -A/D + A/E A -A/C -A/D A -A/C -A/D A A/C A C A/D A D A/E A E System.out.println(big-small) System.out.println System.out System System.out big-small big small 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
import java.util.*;

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 E = lcm(C,D);
    
    long big = B - B/C - B/D + B/E;
    long small = A -A/C -A/D + A/E;
    System.out.println(big-small);
    
  }
  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);
  }
}