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 = lcm(C,D);
    long answer = 0;
    answer = B-A+1;
    answer = answer -(B/C)+((A-1)/C);
    answer = answer -(B/D)+((A-1)/D);
    answer = answer + ((B/LCM)-((A-1)/LCM));
    System.out.println(answer);
       
  }
  
  //最大公約数・最小公倍数（セットで使う）
  static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
  static long lcm (long a, long b) {return a*b/gcd(a,b);}
} 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 = lcm(C,D);
    long answer = 0;
    answer = B-A+1;
    answer = answer -(B/C)+((A-1)/C);
    answer = answer -(B/D)+((A-1)/D);
    answer = answer + ((B/LCM)-((A-1)/LCM));
    System.out.println(answer);
       
  }
  
  //最大公約数・最小公倍数（セットで使う）
  static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
  static long lcm (long a, long b) {return a*b/gcd(a,b);}
} 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 = lcm(C,D);
    long answer = 0;
    answer = B-A+1;
    answer = answer -(B/C)+((A-1)/C);
    answer = answer -(B/D)+((A-1)/D);
    answer = answer + ((B/LCM)-((A-1)/LCM));
    System.out.println(answer);
       
  } 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 = lcm(C,D);
    long answer = 0;
    answer = B-A+1;
    answer = answer -(B/C)+((A-1)/C);
    answer = answer -(B/D)+((A-1)/D);
    answer = answer + ((B/LCM)-((A-1)/LCM));
    System.out.println(answer);
       
  } 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 = lcm(C,D); LCM lcm(C,D) lcm C D long answer = 0; answer 0 answer = B-A+1 answer B-A+1 B-A B A 1 answer = answer -(B/C)+((A-1)/C) answer answer -(B/C)+((A-1)/C) answer -(B/C) answer (B/C) B C ((A-1)/C) (A-1) A 1 C answer = answer -(B/D)+((A-1)/D) answer answer -(B/D)+((A-1)/D) answer -(B/D) answer (B/D) B D ((A-1)/D) (A-1) A 1 D answer = answer + ((B/LCM)-((A-1)/LCM)) answer answer + ((B/LCM)-((A-1)/LCM)) answer ((B/LCM)-((A-1)/LCM)) (B/LCM) B LCM ((A-1)/LCM) (A-1) A 1 LCM System.out.println(answer) System.out.println System.out System System.out answer String[] args args //最大公約数・最小公倍数（セットで使う）
  static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;} gcd {return b>0?gcd(b,a%b):a;} return b>0?gcd(b,a%b):a; b>0?gcd(b,a%b):a b>0 b 0 gcd(b,a%b) gcd b a%b a b a long a a long b b static long lcm (long a, long b) {return a*b/gcd(a,b);} lcm {return a*b/gcd(a,b);} return a*b/gcd(a,b); a*b/gcd(a,b) a*b a b gcd(a,b) gcd a b long a a long b b 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 = lcm(C,D);
    long answer = 0;
    answer = B-A+1;
    answer = answer -(B/C)+((A-1)/C);
    answer = answer -(B/D)+((A-1)/D);
    answer = answer + ((B/LCM)-((A-1)/LCM));
    System.out.println(answer);
       
  }
  
  //最大公約数・最小公倍数（セットで使う）
  static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
  static long lcm (long a, long b) {return a*b/gcd(a,b);}
} 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 = lcm(C,D);
    long answer = 0;
    answer = B-A+1;
    answer = answer -(B/C)+((A-1)/C);
    answer = answer -(B/D)+((A-1)/D);
    answer = answer + ((B/LCM)-((A-1)/LCM));
    System.out.println(answer);
       
  }
  
  //最大公約数・最小公倍数（セットで使う）
  static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
  static long lcm (long a, long b) {return a*b/gcd(a,b);}
} 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 = lcm(C,D);
    long answer = 0;
    answer = B-A+1;
    answer = answer -(B/C)+((A-1)/C);
    answer = answer -(B/D)+((A-1)/D);
    answer = answer + ((B/LCM)-((A-1)/LCM));
    System.out.println(answer);
       
  }
  
  //最大公約数・最小公倍数（セットで使う）
  static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
  static long lcm (long a, long b) {return a*b/gcd(a,b);}
}