import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long A =  Long.parseLong(W.split(" ")[0]);
		long B =  Long.parseLong(W.split(" ")[1]);
		long C =  Long.parseLong(W.split(" ")[2]);
		long D =  Long.parseLong(W.split(" ")[3]);

		A = A-1;
		long N = B - A ;

		long lcm = lcm(C,D);

		long AmodC = A /C;
		long AmodD = A /D;
		long AmodLCM = A/(lcm);

		long BmodC = B /C;
		long BmodD = B /D;
		long BmodLCM = B/(lcm);

		long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM);


		System.out.println(ans);
	}


	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long A =  Long.parseLong(W.split(" ")[0]);
		long B =  Long.parseLong(W.split(" ")[1]);
		long C =  Long.parseLong(W.split(" ")[2]);
		long D =  Long.parseLong(W.split(" ")[3]);

		A = A-1;
		long N = B - A ;

		long lcm = lcm(C,D);

		long AmodC = A /C;
		long AmodD = A /D;
		long AmodLCM = A/(lcm);

		long BmodC = B /C;
		long BmodD = B /D;
		long BmodLCM = B/(lcm);

		long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM);


		System.out.println(ans);
	}


	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

} Main public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long A =  Long.parseLong(W.split(" ")[0]);
		long B =  Long.parseLong(W.split(" ")[1]);
		long C =  Long.parseLong(W.split(" ")[2]);
		long D =  Long.parseLong(W.split(" ")[3]);

		A = A-1;
		long N = B - A ;

		long lcm = lcm(C,D);

		long AmodC = A /C;
		long AmodD = A /D;
		long AmodLCM = A/(lcm);

		long BmodC = B /C;
		long BmodD = B /D;
		long BmodLCM = B/(lcm);

		long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM);


		System.out.println(ans);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long A =  Long.parseLong(W.split(" ")[0]);
		long B =  Long.parseLong(W.split(" ")[1]);
		long C =  Long.parseLong(W.split(" ")[2]);
		long D =  Long.parseLong(W.split(" ")[3]);

		A = A-1;
		long N = B - A ;

		long lcm = lcm(C,D);

		long AmodC = A /C;
		long AmodD = A /D;
		long AmodLCM = A/(lcm);

		long BmodC = B /C;
		long BmodD = B /D;
		long BmodLCM = B/(lcm);

		long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM);


		System.out.println(ans);
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) String W = in.readLine(); W in.readLine() in.readLine in long A =  Long.parseLong(W.split(" ")[0]); A Long.parseLong(W.split(" ")[0]) Long.parseLong Long W.split(" ")[0] W.split(" ") W.split W " " 0 long B =  Long.parseLong(W.split(" ")[1]); B Long.parseLong(W.split(" ")[1]) Long.parseLong Long W.split(" ")[1] W.split(" ") W.split W " " 1 long C =  Long.parseLong(W.split(" ")[2]); C Long.parseLong(W.split(" ")[2]) Long.parseLong Long W.split(" ")[2] W.split(" ") W.split W " " 2 long D =  Long.parseLong(W.split(" ")[3]); D Long.parseLong(W.split(" ")[3]) Long.parseLong Long W.split(" ")[3] W.split(" ") W.split W " " 3 A = A-1 A A-1 A 1 long N = B - A ; N B - A B A long lcm = lcm(C,D); lcm lcm(C,D) lcm C D long AmodC = A /C; AmodC A /C A C long AmodD = A /D; AmodD A /D A D long AmodLCM = A/(lcm); AmodLCM A/(lcm) A (lcm) long BmodC = B /C; BmodC B /C B C long BmodD = B /D; BmodD B /D B D long BmodLCM = B/(lcm); BmodLCM B/(lcm) B (lcm) long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM); ans N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM) N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM) N - BmodC - BmodD N - BmodC - BmodD N BmodC BmodD BmodLCM (AmodC + AmodD - AmodLCM) AmodC + AmodD AmodC AmodD AmodLCM System.out.println(ans) System.out.println System.out System System.out ans String[] args args static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	} lcm {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(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 (long)(c/b); (long)(c/b) c b long a a long b b public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long A =  Long.parseLong(W.split(" ")[0]);
		long B =  Long.parseLong(W.split(" ")[1]);
		long C =  Long.parseLong(W.split(" ")[2]);
		long D =  Long.parseLong(W.split(" ")[3]);

		A = A-1;
		long N = B - A ;

		long lcm = lcm(C,D);

		long AmodC = A /C;
		long AmodD = A /D;
		long AmodLCM = A/(lcm);

		long BmodC = B /C;
		long BmodD = B /D;
		long BmodLCM = B/(lcm);

		long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM);


		System.out.println(ans);
	}


	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

} public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long A =  Long.parseLong(W.split(" ")[0]);
		long B =  Long.parseLong(W.split(" ")[1]);
		long C =  Long.parseLong(W.split(" ")[2]);
		long D =  Long.parseLong(W.split(" ")[3]);

		A = A-1;
		long N = B - A ;

		long lcm = lcm(C,D);

		long AmodC = A /C;
		long AmodD = A /D;
		long AmodLCM = A/(lcm);

		long BmodC = B /C;
		long BmodD = B /D;
		long BmodLCM = B/(lcm);

		long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM);


		System.out.println(ans);
	}


	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long A =  Long.parseLong(W.split(" ")[0]);
		long B =  Long.parseLong(W.split(" ")[1]);
		long C =  Long.parseLong(W.split(" ")[2]);
		long D =  Long.parseLong(W.split(" ")[3]);

		A = A-1;
		long N = B - A ;

		long lcm = lcm(C,D);

		long AmodC = A /C;
		long AmodD = A /D;
		long AmodLCM = A/(lcm);

		long BmodC = B /C;
		long BmodD = B /D;
		long BmodLCM = B/(lcm);

		long ans = N - BmodC - BmodD + BmodLCM + (AmodC + AmodD - AmodLCM);


		System.out.println(ans);
	}


	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

}
