import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      int flg=0;
      long A = sc.nextLong();
      long B = sc.nextLong();
      long C = sc.nextLong();
      long D = sc.nextLong();
      
      long lcm = LCM(C,D);
      
      cnt = -A+B+1;
      long cnt2 = 0;
      long cnt3 = 0;
      long cnt4 = 0;
      
	  cnt2=(long) (A-1)/C;
	  cnt2=(long) B/C-cnt2;
	  cnt3=(long) (A-1)/D;
	  cnt3=(long) B/D-cnt3;
	  cnt4=(long) (A-1)/lcm;
	  cnt4=(long) B/lcm-cnt4;
//      System.out.println(cnt);    	  
//      System.out.println(cnt2);    	  
//      System.out.println(cnt3);    	  
//      System.out.println(cnt4);    	  
      
      System.out.println(cnt-cnt2-cnt3+cnt4);    	  
  }
  
  static long GCD(long a,long b) {
	  long tmp;
	  long r;
	  if(a<b) {
		  tmp = a;
		  a = b;
		  b = tmp;				  
	  }
	  
	  r = a % b;
	  while(r!=0) {
		  a=b;
		  b=r;
		  r=a%b;
	  }
	  
	  return b;
  }
  
  static long LCM(long a,long b) {
	  return a*b/GCD(a,b);
  }
} import java.util.*; util.* java class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      int flg=0;
      long A = sc.nextLong();
      long B = sc.nextLong();
      long C = sc.nextLong();
      long D = sc.nextLong();
      
      long lcm = LCM(C,D);
      
      cnt = -A+B+1;
      long cnt2 = 0;
      long cnt3 = 0;
      long cnt4 = 0;
      
	  cnt2=(long) (A-1)/C;
	  cnt2=(long) B/C-cnt2;
	  cnt3=(long) (A-1)/D;
	  cnt3=(long) B/D-cnt3;
	  cnt4=(long) (A-1)/lcm;
	  cnt4=(long) B/lcm-cnt4;
//      System.out.println(cnt);    	  
//      System.out.println(cnt2);    	  
//      System.out.println(cnt3);    	  
//      System.out.println(cnt4);    	  
      
      System.out.println(cnt-cnt2-cnt3+cnt4);    	  
  }
  
  static long GCD(long a,long b) {
	  long tmp;
	  long r;
	  if(a<b) {
		  tmp = a;
		  a = b;
		  b = tmp;				  
	  }
	  
	  r = a % b;
	  while(r!=0) {
		  a=b;
		  b=r;
		  r=a%b;
	  }
	  
	  return b;
  }
  
  static long LCM(long a,long b) {
	  return a*b/GCD(a,b);
  }
} Main static int mod=1_000_000_007; mod 1_000_000_007 public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      int flg=0;
      long A = sc.nextLong();
      long B = sc.nextLong();
      long C = sc.nextLong();
      long D = sc.nextLong();
      
      long lcm = LCM(C,D);
      
      cnt = -A+B+1;
      long cnt2 = 0;
      long cnt3 = 0;
      long cnt4 = 0;
      
	  cnt2=(long) (A-1)/C;
	  cnt2=(long) B/C-cnt2;
	  cnt3=(long) (A-1)/D;
	  cnt3=(long) B/D-cnt3;
	  cnt4=(long) (A-1)/lcm;
	  cnt4=(long) B/lcm-cnt4;
//      System.out.println(cnt);    	  
//      System.out.println(cnt2);    	  
//      System.out.println(cnt3);    	  
//      System.out.println(cnt4);    	  
      
      System.out.println(cnt-cnt2-cnt3+cnt4);    	  
  } main {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      int flg=0;
      long A = sc.nextLong();
      long B = sc.nextLong();
      long C = sc.nextLong();
      long D = sc.nextLong();
      
      long lcm = LCM(C,D);
      
      cnt = -A+B+1;
      long cnt2 = 0;
      long cnt3 = 0;
      long cnt4 = 0;
      
	  cnt2=(long) (A-1)/C;
	  cnt2=(long) B/C-cnt2;
	  cnt3=(long) (A-1)/D;
	  cnt3=(long) B/D-cnt3;
	  cnt4=(long) (A-1)/lcm;
	  cnt4=(long) B/lcm-cnt4;
//      System.out.println(cnt);    	  
//      System.out.println(cnt2);    	  
//      System.out.println(cnt3);    	  
//      System.out.println(cnt4);    	  
      
      System.out.println(cnt-cnt2-cnt3+cnt4);    	  
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long cnt =0; cnt 0 int flg=0; flg 0 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 cnt = -A+B+1 cnt -A+B+1 -A+B+1 -A A B 1 long cnt2 = 0; cnt2 0 long cnt3 = 0; cnt3 0 long cnt4 = 0; cnt4 0 cnt2=(long) (A-1)/C cnt2 (long) (A-1)/C (long) (A-1) A 1 C cnt2=(long) B/C-cnt2 cnt2 (long) B/C-cnt2 (long) B/C (long) B C cnt2 cnt3=(long) (A-1)/D cnt3 (long) (A-1)/D (long) (A-1) A 1 D cnt3=(long) B/D-cnt3 cnt3 (long) B/D-cnt3 (long) B/D (long) B D cnt3 cnt4=(long) (A-1)/lcm cnt4 (long) (A-1)/lcm (long) (A-1) A 1 lcm cnt4=(long) B/lcm-cnt4 cnt4 (long) B/lcm-cnt4 (long) B/lcm (long) B lcm cnt4 System.out.println(cnt-cnt2-cnt3+cnt4) System.out.println System.out System System.out cnt-cnt2-cnt3+cnt4 cnt-cnt2-cnt3 cnt-cnt2-cnt3 cnt cnt2 cnt3 cnt4 String[] args args static long GCD(long a,long b) {
	  long tmp;
	  long r;
	  if(a<b) {
		  tmp = a;
		  a = b;
		  b = tmp;				  
	  }
	  
	  r = a % b;
	  while(r!=0) {
		  a=b;
		  b=r;
		  r=a%b;
	  }
	  
	  return b;
  } GCD {
	  long tmp;
	  long r;
	  if(a<b) {
		  tmp = a;
		  a = b;
		  b = tmp;				  
	  }
	  
	  r = a % b;
	  while(r!=0) {
		  a=b;
		  b=r;
		  r=a%b;
	  }
	  
	  return b;
  } long tmp; tmp long r; r if(a<b) {
		  tmp = a;
		  a = b;
		  b = tmp;				  
	  } a<b a b {
		  tmp = a;
		  a = b;
		  b = tmp;				  
	  } tmp = a tmp a a = b a b b = tmp b tmp r = a % b r a % b a b while(r!=0) {
		  a=b;
		  b=r;
		  r=a%b;
	  } r!=0 r 0 {
		  a=b;
		  b=r;
		  r=a%b;
	  } a=b a b b=r b r r=a%b r a%b a b return b; b 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
import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      int flg=0;
      long A = sc.nextLong();
      long B = sc.nextLong();
      long C = sc.nextLong();
      long D = sc.nextLong();
      
      long lcm = LCM(C,D);
      
      cnt = -A+B+1;
      long cnt2 = 0;
      long cnt3 = 0;
      long cnt4 = 0;
      
	  cnt2=(long) (A-1)/C;
	  cnt2=(long) B/C-cnt2;
	  cnt3=(long) (A-1)/D;
	  cnt3=(long) B/D-cnt3;
	  cnt4=(long) (A-1)/lcm;
	  cnt4=(long) B/lcm-cnt4;
//      System.out.println(cnt);    	  
//      System.out.println(cnt2);    	  
//      System.out.println(cnt3);    	  
//      System.out.println(cnt4);    	  
      
      System.out.println(cnt-cnt2-cnt3+cnt4);    	  
  }
  
  static long GCD(long a,long b) {
	  long tmp;
	  long r;
	  if(a<b) {
		  tmp = a;
		  a = b;
		  b = tmp;				  
	  }
	  
	  r = a % b;
	  while(r!=0) {
		  a=b;
		  b=r;
		  r=a%b;
	  }
	  
	  return b;
  }
  
  static long LCM(long a,long b) {
	  return a*b/GCD(a,b);
  }
}