import java.util.*;
import static java.lang.System.*;

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

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	}
  //最小公倍数を求めるメソッド
  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 import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; 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();
	  

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	}
  //最小公倍数を求めるメソッド
  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();
	  long B = sc.nextLong();
	  long C = sc.nextLong();
	  long D = sc.nextLong();
	  

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	} main {
	  Scanner sc = new Scanner(System.in);
	  
	  long A = sc.nextLong();
	  long B = sc.nextLong();
	  long C = sc.nextLong();
	  long D = sc.nextLong();
	  

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	} 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 A-- A long c = A/C; c A/C A C long d = A/D; d A/D A D long cANDd = A / lcm(C,D); cANDd A / lcm(C,D) A lcm(C,D) lcm C D long a = A - (c + d - cANDd); a A - (c + d - cANDd) A (c + d - cANDd) c + d c d cANDd c = B/C c B/C B C d = B/D d B/D B D cANDd = B / lcm(C,D) cANDd B / lcm(C,D) B lcm(C,D) lcm C D long b = B - (c + d - cANDd); b B - (c + d - cANDd) B (c + d - cANDd) c + d c d cANDd out.println(b - a) out.println out b - a b a 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 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();
	  

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	}
  //最小公倍数を求めるメソッド
  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);
	}
  } 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();
	  

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	}
  //最小公倍数を求めるメソッド
  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
import java.util.*;
import static java.lang.System.*;

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

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	}
  //最小公倍数を求めるメソッド
  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);
	}
  }	