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 lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  }
  
  private static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
  
  private static long count(long n, long C, long D, long lcm) {
    return n - n/C - n/D + n/lcm;
  }
} 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 lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  }
  
  private static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
  
  private static long count(long n, long C, long D, long lcm) {
    return n - n/C - n/D + n/lcm;
  }
} 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 lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  } main {
 
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
 
    long lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  } 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 lcm = (C * D) / gcd(D, C); lcm (C * D) / gcd(D, C) (C * D) C D gcd(D, C) gcd D C System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm)) System.out.println System.out System System.out count(B, C, D, lcm) - count(A-1, C, D, lcm) count(B, C, D, lcm) count B C D lcm count(A-1, C, D, lcm) count A-1 A 1 C D lcm String[] args args private static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  } gcd {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  } if (b == 0) {
      return a;
    } b == 0 b 0 {
      return a;
    } return a; a return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b long a a long b b private static long count(long n, long C, long D, long lcm) {
    return n - n/C - n/D + n/lcm;
  } count {
    return n - n/C - n/D + n/lcm;
  } return n - n/C - n/D + n/lcm; n - n/C - n/D + n/lcm n - n/C - n/D n - n/C - n/D n n/C n C n/D n D n/lcm n lcm long n n long C C long D D long lcm lcm 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 lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  }
  
  private static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
  
  private static long count(long n, long C, long D, long lcm) {
    return n - n/C - n/D + n/lcm;
  }
} 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 lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  }
  
  private static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
  
  private static long count(long n, long C, long D, long lcm) {
    return n - n/C - n/D + n/lcm;
  }
} 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 lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  }
  
  private static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
  
  private static long count(long n, long C, long D, long lcm) {
    return n - n/C - n/D + n/lcm;
  }
}