import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{	
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	long a = Long.parseLong(sc.next());
	long b = Long.parseLong(sc.next());
	long c = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long s = 0;
	
	
	if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	}	
	
	
	System.out.println(s);
}
private static long lcm(long a, long b){ 	
	return a*b/gcd(a,b);
}
private static long gcd(long a, long b){
	if(a<b) return gcd(b,a);
	if(b==0)return a;
	return gcd(b,a%b);
}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main{	
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	long a = Long.parseLong(sc.next());
	long b = Long.parseLong(sc.next());
	long c = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long s = 0;
	
	
	if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	}	
	
	
	System.out.println(s);
}
private static long lcm(long a, long b){ 	
	return a*b/gcd(a,b);
}
private static long gcd(long a, long b){
	if(a<b) return gcd(b,a);
	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 = Long.parseLong(sc.next());
	long b = Long.parseLong(sc.next());
	long c = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long s = 0;
	
	
	if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	}	
	
	
	System.out.println(s);
} main {
	Scanner sc = new Scanner(System.in);
	long a = Long.parseLong(sc.next());
	long b = Long.parseLong(sc.next());
	long c = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long s = 0;
	
	
	if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	}	
	
	
	System.out.println(s);
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c = Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d = Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long s = 0; s 0 if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	} c!=d c d {
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	} long z = lcm(c,d); z lcm(c,d) lcm c d long x = b/c - (a-1)/c; x b/c - (a-1)/c b/c b c (a-1)/c (a-1) a 1 c long y = b/d - (a-1)/d; y b/d - (a-1)/d b/d b d (a-1)/d (a-1) a 1 d long w = b/z - (a-1)/z; w b/z - (a-1)/z b/z b z (a-1)/z (a-1) a 1 z s = b-a+1-x-y+w s b-a+1-x-y+w b-a+1-x-y b-a+1-x-y b-a+1 b-a b a 1 x y w {
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	} long x = b/c - (a-1)/c; x b/c - (a-1)/c b/c b c (a-1)/c (a-1) a 1 c s = b-a+1-x s b-a+1-x b-a+1 b-a b a 1 x System.out.println(s) System.out.println System.out System System.out s 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(a<b) return gcd(b,a);
	if(b==0)return a;
	return gcd(b,a%b);
} gcd {
	if(a<b) return gcd(b,a);
	if(b==0)return a;
	return gcd(b,a%b);
} if(a<b) return gcd(b,a); a<b a b return gcd(b,a); gcd(b,a) gcd b a if(b==0)return a; b==0 b 0 return a; a return gcd(b,a%b); gcd(b,a%b) gcd b a%b 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 = Long.parseLong(sc.next());
	long b = Long.parseLong(sc.next());
	long c = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long s = 0;
	
	
	if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	}	
	
	
	System.out.println(s);
}
private static long lcm(long a, long b){ 	
	return a*b/gcd(a,b);
}
private static long gcd(long a, long b){
	if(a<b) return gcd(b,a);
	if(b==0)return a;
	return gcd(b,a%b);
}
} public class Main{	
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	long a = Long.parseLong(sc.next());
	long b = Long.parseLong(sc.next());
	long c = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long s = 0;
	
	
	if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	}	
	
	
	System.out.println(s);
}
private static long lcm(long a, long b){ 	
	return a*b/gcd(a,b);
}
private static long gcd(long a, long b){
	if(a<b) return gcd(b,a);
	if(b==0)return a;
	return gcd(b,a%b);
}
} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{	
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	long a = Long.parseLong(sc.next());
	long b = Long.parseLong(sc.next());
	long c = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long s = 0;
	
	
	if(c!=d){
		long z = lcm(c,d);
		long x = b/c - (a-1)/c;   
		long y = b/d - (a-1)/d;
		long w = b/z - (a-1)/z;
		s = b-a+1-x-y+w;
	}else{
		long x = b/c - (a-1)/c;
		s = b-a+1-x;
	}	
	
	
	System.out.println(s);
}
private static long lcm(long a, long b){ 	
	return a*b/gcd(a,b);
}
private static long gcd(long a, long b){
	if(a<b) return gcd(b,a);
	if(b==0)return a;
	return gcd(b,a%b);
}
}
