import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    }
    

      
    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 scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    }
    

      
    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 scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    } main {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long a = scanner.nextLong(); a scanner.nextLong() scanner.nextLong scanner long b = scanner.nextLong(); b scanner.nextLong() scanner.nextLong scanner long c = scanner.nextLong(); c scanner.nextLong() scanner.nextLong scanner long d = scanner.nextLong(); d scanner.nextLong() scanner.nextLong scanner long size = b-a + 1; size b-a + 1 b-a b a 1 long numOfRemoved= 0; numOfRemoved 0 long numOfMultiplyC = b / c - (a -1) / c; numOfMultiplyC b / c - (a -1) / c b / c b c (a -1) / c (a -1) a 1 c long numOfMultiplyd = b / d - (a-1) / d; numOfMultiplyd b / d - (a-1) / d b / d b d (a-1) / d (a-1) a 1 d long x = c * d / gcd(c, d); x c * d / gcd(c, d) c * d c d gcd(c, d) gcd c d long numOfMultiplycd = b / x - (a-1) / x; numOfMultiplycd b / x - (a-1) / x b / x b x (a-1) / x (a-1) a 1 x System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd) System.out.println System.out System System.out size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd size - numOfMultiplyC - numOfMultiplyd size - numOfMultiplyC - numOfMultiplyd size numOfMultiplyC numOfMultiplyd numOfMultiplycd 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 public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    }
    

      
    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 scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    }
    

      
    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 scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    }
    

      
    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);
  }
}