import java.util.Scanner;

public class Main{
	static long f(long A, long C, long D) {
		if(A == 0) return 0;
		long mulC = A / C, mulD = A / D;
		long mulCD = A / LCM(C, D);
		return A - mulC - mulD + mulCD;
	}
	static long GCD(long x, long y) {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	}
	static long LCM(long x, long y){
		return (x / GCD(x,y)) * y;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		}
	}
} import java.util.Scanner; Scanner java.util public class Main{
	static long f(long A, long C, long D) {
		if(A == 0) return 0;
		long mulC = A / C, mulD = A / D;
		long mulCD = A / LCM(C, D);
		return A - mulC - mulD + mulCD;
	}
	static long GCD(long x, long y) {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	}
	static long LCM(long x, long y){
		return (x / GCD(x,y)) * y;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		}
	}
} Main static long f(long A, long C, long D) {
		if(A == 0) return 0;
		long mulC = A / C, mulD = A / D;
		long mulCD = A / LCM(C, D);
		return A - mulC - mulD + mulCD;
	} f {
		if(A == 0) return 0;
		long mulC = A / C, mulD = A / D;
		long mulCD = A / LCM(C, D);
		return A - mulC - mulD + mulCD;
	} if(A == 0) return 0; A == 0 A 0 return 0; 0 long mulC = A / C mulC A / C A C mulD = A / D; mulD A / D A D long mulCD = A / LCM(C, D); mulCD A / LCM(C, D) A LCM(C, D) LCM C D return A - mulC - mulD + mulCD; A - mulC - mulD + mulCD A - mulC - mulD A - mulC - mulD A mulC mulD mulCD long A A long C C long D D static long GCD(long x, long y) {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	} GCD {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	} if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y); Math.max(x, y) % Math.min(x, y) == 0 Math.max(x, y) % Math.min(x, y) Math.max(x, y) Math.max Math x y Math.min(x, y) Math.min Math x y 0 return Math.min(x, y); Math.min(x, y) Math.min Math x y return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y)); GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y)) GCD Math.min(x, y) Math.min Math x y Math.max(x, y) % Math.min(x, y) Math.max(x, y) Math.max Math x y Math.min(x, y) Math.min Math x y long x x long y y static long LCM(long x, long y){
		return (x / GCD(x,y)) * y;
	} LCM {
		return (x / GCD(x,y)) * y;
	} return (x / GCD(x,y)) * y; (x / GCD(x,y)) * y (x / GCD(x,y)) x GCD(x,y) GCD x y y long x x long y y public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		}
	} main {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		}
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		} sc.hasNext() sc.hasNext sc {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		} long A = sc.nextLong() A sc.nextLong() sc.nextLong sc B = sc.nextLong() B sc.nextLong() sc.nextLong sc C = sc.nextLong() C sc.nextLong() sc.nextLong sc D = sc.nextLong(); D sc.nextLong() sc.nextLong sc System.out.println(f(B, C, D) - f(A - 1, C, D)) System.out.println System.out System System.out f(B, C, D) - f(A - 1, C, D) f(B, C, D) f B C D f(A - 1, C, D) f A - 1 A 1 C D String[] args args public class Main{
	static long f(long A, long C, long D) {
		if(A == 0) return 0;
		long mulC = A / C, mulD = A / D;
		long mulCD = A / LCM(C, D);
		return A - mulC - mulD + mulCD;
	}
	static long GCD(long x, long y) {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	}
	static long LCM(long x, long y){
		return (x / GCD(x,y)) * y;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		}
	}
} public class Main{
	static long f(long A, long C, long D) {
		if(A == 0) return 0;
		long mulC = A / C, mulD = A / D;
		long mulCD = A / LCM(C, D);
		return A - mulC - mulD + mulCD;
	}
	static long GCD(long x, long y) {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	}
	static long LCM(long x, long y){
		return (x / GCD(x,y)) * y;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		}
	}
} Main
import java.util.Scanner;

public class Main{
	static long f(long A, long C, long D) {
		if(A == 0) return 0;
		long mulC = A / C, mulD = A / D;
		long mulCD = A / LCM(C, D);
		return A - mulC - mulD + mulCD;
	}
	static long GCD(long x, long y) {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	}
	static long LCM(long x, long y){
		return (x / GCD(x,y)) * y;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long A = sc.nextLong(), B = sc.nextLong(), C = sc.nextLong(), D = sc.nextLong();
			System.out.println(f(B, C, D) - f(A - 1, C, D));
		}
	}
}