import java.util.Scanner;

public class Main {
	public static void main(String args[]) {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	//int N = std.nextInt();

	//String S = std.next();
	long A = std.nextLong();
	long B = std.nextLong();
	long C = std.nextLong();
	long D = std.nextLong();

	long BBB = Takuma(B,C,D);
	long AAA = Takuma(A-1,C,D);

	long CCC = BBB-AAA;

	System.out.println(CCC);

	}


	public static long Takuma (long B,long C,long D) {

	long g;
	long bigC = B/C;
	long bigD = B/D;
	long CD = C*D;
	long copyC = C;

	//ユークリッドの互除法
	while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	}

	long l = CD/copyC;

	long bigL = B/l;



	long X = B - bigC - bigD + bigL; //B以下でCで割り切れるものとDで割り切れるものの数(重複は無視)

	//B以下でCで割れるものとDで割れるもの

	return X;

	}




	}

 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]) {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	//int N = std.nextInt();

	//String S = std.next();
	long A = std.nextLong();
	long B = std.nextLong();
	long C = std.nextLong();
	long D = std.nextLong();

	long BBB = Takuma(B,C,D);
	long AAA = Takuma(A-1,C,D);

	long CCC = BBB-AAA;

	System.out.println(CCC);

	}


	public static long Takuma (long B,long C,long D) {

	long g;
	long bigC = B/C;
	long bigD = B/D;
	long CD = C*D;
	long copyC = C;

	//ユークリッドの互除法
	while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	}

	long l = CD/copyC;

	long bigL = B/l;



	long X = B - bigC - bigD + bigL; //B以下でCで割り切れるものとDで割り切れるものの数(重複は無視)

	//B以下でCで割れるものとDで割れるもの

	return X;

	}




	} Main public static void main(String args[]) {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	//int N = std.nextInt();

	//String S = std.next();
	long A = std.nextLong();
	long B = std.nextLong();
	long C = std.nextLong();
	long D = std.nextLong();

	long BBB = Takuma(B,C,D);
	long AAA = Takuma(A-1,C,D);

	long CCC = BBB-AAA;

	System.out.println(CCC);

	} main {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	//int N = std.nextInt();

	//String S = std.next();
	long A = std.nextLong();
	long B = std.nextLong();
	long C = std.nextLong();
	long D = std.nextLong();

	long BBB = Takuma(B,C,D);
	long AAA = Takuma(A-1,C,D);

	long CCC = BBB-AAA;

	System.out.println(CCC);

	} Scanner std = new Scanner(System.in); std new Scanner(System.in) long A = std.nextLong(); A std.nextLong() std.nextLong std long B = std.nextLong(); B std.nextLong() std.nextLong std long C = std.nextLong(); C std.nextLong() std.nextLong std long D = std.nextLong(); D std.nextLong() std.nextLong std long BBB = Takuma(B,C,D); BBB Takuma(B,C,D) Takuma B C D long AAA = Takuma(A-1,C,D); AAA Takuma(A-1,C,D) Takuma A-1 A 1 C D long CCC = BBB-AAA; CCC BBB-AAA BBB AAA System.out.println(CCC) System.out.println System.out System System.out CCC String args[] args public static long Takuma (long B,long C,long D) {

	long g;
	long bigC = B/C;
	long bigD = B/D;
	long CD = C*D;
	long copyC = C;

	//ユークリッドの互除法
	while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	}

	long l = CD/copyC;

	long bigL = B/l;



	long X = B - bigC - bigD + bigL; //B以下でCで割り切れるものとDで割り切れるものの数(重複は無視)

	//B以下でCで割れるものとDで割れるもの

	return X;

	} Takuma {

	long g;
	long bigC = B/C;
	long bigD = B/D;
	long CD = C*D;
	long copyC = C;

	//ユークリッドの互除法
	while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	}

	long l = CD/copyC;

	long bigL = B/l;



	long X = B - bigC - bigD + bigL; //B以下でCで割り切れるものとDで割り切れるものの数(重複は無視)

	//B以下でCで割れるものとDで割れるもの

	return X;

	} long g; g long bigC = B/C; bigC B/C B C long bigD = B/D; bigD B/D B D long CD = C*D; CD C*D C D long copyC = C; copyC C while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	} (g = D%copyC) != 0 (g = D%copyC) g D%copyC D copyC 0 {
		D = copyC;
		copyC = g;
	} D = copyC D copyC copyC = g copyC g long l = CD/copyC; l CD/copyC CD copyC long bigL = B/l; bigL B/l B l long X = B - bigC - bigD + bigL; X B - bigC - bigD + bigL B - bigC - bigD B - bigC - bigD B bigC bigD bigL return X; X long B B long C C long D D public class Main {
	public static void main(String args[]) {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	//int N = std.nextInt();

	//String S = std.next();
	long A = std.nextLong();
	long B = std.nextLong();
	long C = std.nextLong();
	long D = std.nextLong();

	long BBB = Takuma(B,C,D);
	long AAA = Takuma(A-1,C,D);

	long CCC = BBB-AAA;

	System.out.println(CCC);

	}


	public static long Takuma (long B,long C,long D) {

	long g;
	long bigC = B/C;
	long bigD = B/D;
	long CD = C*D;
	long copyC = C;

	//ユークリッドの互除法
	while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	}

	long l = CD/copyC;

	long bigL = B/l;



	long X = B - bigC - bigD + bigL; //B以下でCで割り切れるものとDで割り切れるものの数(重複は無視)

	//B以下でCで割れるものとDで割れるもの

	return X;

	}




	} public class Main {
	public static void main(String args[]) {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	//int N = std.nextInt();

	//String S = std.next();
	long A = std.nextLong();
	long B = std.nextLong();
	long C = std.nextLong();
	long D = std.nextLong();

	long BBB = Takuma(B,C,D);
	long AAA = Takuma(A-1,C,D);

	long CCC = BBB-AAA;

	System.out.println(CCC);

	}


	public static long Takuma (long B,long C,long D) {

	long g;
	long bigC = B/C;
	long bigD = B/D;
	long CD = C*D;
	long copyC = C;

	//ユークリッドの互除法
	while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	}

	long l = CD/copyC;

	long bigL = B/l;



	long X = B - bigC - bigD + bigL; //B以下でCで割り切れるものとDで割り切れるものの数(重複は無視)

	//B以下でCで割れるものとDで割れるもの

	return X;

	}




	} Main
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	//int N = std.nextInt();

	//String S = std.next();
	long A = std.nextLong();
	long B = std.nextLong();
	long C = std.nextLong();
	long D = std.nextLong();

	long BBB = Takuma(B,C,D);
	long AAA = Takuma(A-1,C,D);

	long CCC = BBB-AAA;

	System.out.println(CCC);

	}


	public static long Takuma (long B,long C,long D) {

	long g;
	long bigC = B/C;
	long bigD = B/D;
	long CD = C*D;
	long copyC = C;

	//ユークリッドの互除法
	while((g = D%copyC) != 0) {
		D = copyC;
		copyC = g;
	}

	long l = CD/copyC;

	long bigL = B/l;



	long X = B - bigC - bigD + bigL; //B以下でCで割り切れるものとDで割り切れるものの数(重複は無視)

	//B以下でCで割れるものとDで割れるもの

	return X;

	}




	}


