import java.util.Scanner;
public class Main{
 
//最小公倍数lcm
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return c/b;
}
  
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong()-1;
   long B = sc.nextLong();
   long C = sc.nextInt();
   long D = sc.nextInt();
   
   long lcm_cd = 0;
   long sum_B = 0;
   long sum_A = 0;
   if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } 
   sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) );
   sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) );
   System.out.println(sum_B-sum_A);
 }
} import java.util.Scanner; Scanner java.util public class Main{
 
//最小公倍数lcm
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return c/b;
}
  
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong()-1;
   long B = sc.nextLong();
   long C = sc.nextInt();
   long D = sc.nextInt();
   
   long lcm_cd = 0;
   long sum_B = 0;
   long sum_A = 0;
   if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } 
   sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) );
   sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) );
   System.out.println(sum_B-sum_A);
 }
} Main //最小公倍数lcm
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return c/b;
} lcm {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return c/b;
} long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
		a = b;
		b = temp;
	} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
		a = b;
		b = temp;
	} a = b a b b = temp b temp return c/b; c/b c b long a a long b b public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong()-1;
   long B = sc.nextLong();
   long C = sc.nextInt();
   long D = sc.nextInt();
   
   long lcm_cd = 0;
   long sum_B = 0;
   long sum_A = 0;
   if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } 
   sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) );
   sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) );
   System.out.println(sum_B-sum_A);
 } main {
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong()-1;
   long B = sc.nextLong();
   long C = sc.nextInt();
   long D = sc.nextInt();
   
   long lcm_cd = 0;
   long sum_B = 0;
   long sum_A = 0;
   if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } 
   sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) );
   sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) );
   System.out.println(sum_B-sum_A);
 } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = sc.nextLong()-1; A sc.nextLong()-1 sc.nextLong() sc.nextLong sc 1 long B = sc.nextLong(); B sc.nextLong() sc.nextLong sc long C = sc.nextInt(); C sc.nextInt() sc.nextInt sc long D = sc.nextInt(); D sc.nextInt() sc.nextInt sc long lcm_cd = 0; lcm_cd 0 long sum_B = 0; sum_B 0 long sum_A = 0; sum_A 0 if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } C >=D C D {
    lcm_cd = lcm(C,D);
   } lcm_cd = lcm(C,D) lcm_cd lcm(C,D) lcm C D {
     lcm_cd = lcm(D,C);
   } lcm_cd = lcm(D,C) lcm_cd lcm(D,C) lcm D C sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) ) sum_B B - ( (B/C) + (B/D) - (B/lcm_cd) ) B ( (B/C) + (B/D) - (B/lcm_cd) ) (B/C) + (B/D) (B/C) B C (B/D) B D (B/lcm_cd) B lcm_cd sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) ) sum_A A - ( (A/C) + (A/D) - (A/lcm_cd) ) A ( (A/C) + (A/D) - (A/lcm_cd) ) (A/C) + (A/D) (A/C) A C (A/D) A D (A/lcm_cd) A lcm_cd System.out.println(sum_B-sum_A) System.out.println System.out System System.out sum_B-sum_A sum_B sum_A String[] args args public class Main{
 
//最小公倍数lcm
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return c/b;
}
  
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong()-1;
   long B = sc.nextLong();
   long C = sc.nextInt();
   long D = sc.nextInt();
   
   long lcm_cd = 0;
   long sum_B = 0;
   long sum_A = 0;
   if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } 
   sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) );
   sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) );
   System.out.println(sum_B-sum_A);
 }
} public class Main{
 
//最小公倍数lcm
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return c/b;
}
  
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong()-1;
   long B = sc.nextLong();
   long C = sc.nextInt();
   long D = sc.nextInt();
   
   long lcm_cd = 0;
   long sum_B = 0;
   long sum_A = 0;
   if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } 
   sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) );
   sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) );
   System.out.println(sum_B-sum_A);
 }
} Main
import java.util.Scanner;
public class Main{
 
//最小公倍数lcm
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return c/b;
}
  
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong()-1;
   long B = sc.nextLong();
   long C = sc.nextInt();
   long D = sc.nextInt();
   
   long lcm_cd = 0;
   long sum_B = 0;
   long sum_A = 0;
   if(C >=D) 
   {
    lcm_cd = lcm(C,D);
   }
   else 
   {
     lcm_cd = lcm(D,C);
   } 
   sum_B = B - ( (B/C) + (B/D) - (B/lcm_cd) );
   sum_A = A - ( (A/C) + (A/D) - (A/lcm_cd) );
   System.out.println(sum_B-sum_A);
 }
}