import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
  		long ans=0;
  		long ansa=0;
  		long ansb=0;
        long divide=lcm(c,d);
		ansb=b-(b/c+b/d-b/divide);
        ansa=a-1-((a-1)/c+(a-1)/d-(a-1)/divide);
  		ans=ansb-ansa;
    	System.out.println(ans);
    }
  private static long lcm(long a, long b){
  return a*b/gcd(a,b);
}
  private static long gcd(long a,long b){
   if(b==0){
   	return a;
   }
	return gcd(b, a%b);
}
} import java.util.*; util.* java class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
  		long ans=0;
  		long ansa=0;
  		long ansb=0;
        long divide=lcm(c,d);
		ansb=b-(b/c+b/d-b/divide);
        ansa=a-1-((a-1)/c+(a-1)/d-(a-1)/divide);
  		ans=ansb-ansa;
    	System.out.println(ans);
    }
  private static long lcm(long a, long b){
  return a*b/gcd(a,b);
}
  private static long gcd(long a,long b){
   if(b==0){
   	return a;
   }
	return gcd(b, a%b);
}
} Main public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
  		long ans=0;
  		long ansa=0;
  		long ansb=0;
        long divide=lcm(c,d);
		ansb=b-(b/c+b/d-b/divide);
        ansa=a-1-((a-1)/c+(a-1)/d-(a-1)/divide);
  		ans=ansb-ansa;
    	System.out.println(ans);
    } main {
	Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
  		long ans=0;
  		long ansa=0;
  		long ansb=0;
        long divide=lcm(c,d);
		ansb=b-(b/c+b/d-b/divide);
        ansa=a-1-((a-1)/c+(a-1)/d-(a-1)/divide);
  		ans=ansb-ansa;
    	System.out.println(ans);
    } 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 int c=sc.nextInt(); c sc.nextInt() sc.nextInt sc int d=sc.nextInt(); d sc.nextInt() sc.nextInt sc long ans=0; ans 0 long ansa=0; ansa 0 long ansb=0; ansb 0 long divide=lcm(c,d); divide lcm(c,d) lcm c d ansb=b-(b/c+b/d-b/divide) ansb b-(b/c+b/d-b/divide) b (b/c+b/d-b/divide) b/c+b/d b/c b c b/d b d b/divide b divide ansa=a-1-((a-1)/c+(a-1)/d-(a-1)/divide) ansa a-1-((a-1)/c+(a-1)/d-(a-1)/divide) a-1-((a-1)/c+(a-1)/d-(a-1)/divide) a 1 ((a-1)/c+(a-1)/d-(a-1)/divide) (a-1)/c+(a-1)/d (a-1)/c (a-1) a 1 c (a-1)/d (a-1) a 1 d (a-1)/divide (a-1) a 1 divide ans=ansb-ansa ans ansb-ansa ansb ansa System.out.println(ans) System.out.println System.out System System.out ans String[] args args private 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 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
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
  		long ans=0;
  		long ansa=0;
  		long ansb=0;
        long divide=lcm(c,d);
		ansb=b-(b/c+b/d-b/divide);
        ansa=a-1-((a-1)/c+(a-1)/d-(a-1)/divide);
  		ans=ansb-ansa;
    	System.out.println(ans);
    }
  private static long lcm(long a, long b){
  return a*b/gcd(a,b);
}
  private static long gcd(long a,long b){
   if(b==0){
   	return a;
   }
	return gcd(b, a%b);
}
}