import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	long A, B, C, D;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		A = in.nextLong(); B = in.nextLong(); C = in.nextLong(); D = in.nextLong();
		out.println((f(B) - f(A-1)));
	}
	
	long f(long X){
		return X - (X / C + X / D - X / (lcm(C, D)));
	}
	
	long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	
	long lcm(long a, long b){
		return a / gcd(a, b) * b; //オーバーフローに注意
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
} import java.io.*; io.* java import java.lang.reflect.Array; Array java.lang.reflect import java.util.*; util.* java import java.util.Map.Entry; Entry java.util.Map import java.util.function.Function; Function java.util.function import java.util.stream.Collectors; Collectors java.util.stream public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	long A, B, C, D;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		A = in.nextLong(); B = in.nextLong(); C = in.nextLong(); D = in.nextLong();
		out.println((f(B) - f(A-1)));
	}
	
	long f(long X){
		return X - (X / C + X / D - X / (lcm(C, D)));
	}
	
	long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	
	long lcm(long a, long b){
		return a / gcd(a, b) * b; //オーバーフローに注意
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
} Main String fileName = "input.txt"; fileName "input.txt" final boolean isDebug = false; isDebug false //final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in); in new FastScanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) final int MOD = (int)1e9+7; MOD (int)1e9+7 (int)1e9 7 final long INF = Long.MAX_VALUE / 2; INF Long.MAX_VALUE / 2 Long.MAX_VALUE Long Long.MAX_VALUE 2 long A A B B C C D; D //System.out.println();はつかわない！！
	void solve() throws Exception{
		A = in.nextLong(); B = in.nextLong(); C = in.nextLong(); D = in.nextLong();
		out.println((f(B) - f(A-1)));
	} solve {
		A = in.nextLong(); B = in.nextLong(); C = in.nextLong(); D = in.nextLong();
		out.println((f(B) - f(A-1)));
	} A = in.nextLong() A in.nextLong() in.nextLong in B = in.nextLong() B in.nextLong() in.nextLong in C = in.nextLong() C in.nextLong() in.nextLong in D = in.nextLong() D in.nextLong() in.nextLong in out.println((f(B) - f(A-1))) out.println out (f(B) - f(A-1)) f(B) f B f(A-1) f A-1 A 1 long f(long X){
		return X - (X / C + X / D - X / (lcm(C, D)));
	} f {
		return X - (X / C + X / D - X / (lcm(C, D)));
	} return X - (X / C + X / D - X / (lcm(C, D))); X - (X / C + X / D - X / (lcm(C, D))) X (X / C + X / D - X / (lcm(C, D))) X / C + X / D X / C X C X / D X D X / (lcm(C, D)) X (lcm(C, D)) lcm C D long X X long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	} gcd {
		return b == 0 ? a : gcd(b, a % b);
	} return b == 0 ? a : gcd(b, a % b); b == 0 ? a : gcd(b, a % b) b == 0 b 0 a gcd(b, a % b) gcd b a % b a b long a a long b b long lcm(long a, long b){
		return a / gcd(a, b) * b; //オーバーフローに注意
	} lcm {
		return a / gcd(a, b) * b; //オーバーフローに注意
	} return a / gcd(a, b) * b; //オーバーフローに注意 a / gcd(a, b) * b a / gcd(a, b) a gcd(a, b) gcd a b b long a a long b b /* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	} main {
		new Main().m();
	} new Main().m() new Main().m new Main() String[] args args void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	} m {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	} if(isDebug) in = new FastScanner(new FileInputStream(fileName)); isDebug in = new FastScanner(new FileInputStream(fileName)) in new FastScanner(new FileInputStream(fileName)) solve() solve out.flush() out.flush out class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
} FastScanner Reader input; input FastScanner() {this(System.in);} FastScanner {this(System.in);} this(System.in) this System.in System System.in FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));} FastScanner {this.input = new BufferedReader(new InputStreamReader(stream));} this.input = new BufferedReader(new InputStreamReader(stream)) this.input this this.input new BufferedReader(new InputStreamReader(stream)) InputStream stream stream int nextInt() {return (int) nextLong();} nextInt {return (int) nextLong();} return (int) nextLong(); (int) nextLong() nextLong long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	} nextLong {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	} try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		} IOException e {
			e.printStackTrace();
			return -1;
		} e.printStackTrace() e.printStackTrace e return -1; -1 1 {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} int sign = 1; sign 1 int b = input.read(); b input.read() input.read input while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			} (b < '0' || '9' < b) && b != '-' && b != '+' (b < '0' || '9' < b) && b != '-' && b != '+' (b < '0' || '9' < b) b < '0' b '0' '9' < b '9' b b != '-' b '-' b != '+' b '+' {
				b = input.read();
			} b = input.read() b input.read() input.read input if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			} b == '-' b '-' {
				sign = -1;
				b = input.read();
			} sign = -1 sign -1 1 b = input.read() b input.read() input.read input if (b == '+') {
				b = input.read();
			} b == '+' b '+' {
				b = input.read();
			} b = input.read() b input.read() input.read input long ret = b - '0'; ret b - '0' b '0' while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			} true {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			} b = input.read() b input.read() input.read input if (b < '0' || '9' < b) return ret * sign; b < '0' || '9' < b b < '0' b '0' '9' < b '9' b return ret * sign; ret * sign ret sign ret *= 10 ret 10 ret += b - '0' ret b - '0' b '0' double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	} nextDouble {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	} try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		} IOException e {
			e.printStackTrace();
			return Double.NaN;
		} e.printStackTrace() e.printStackTrace e return Double.NaN; Double.NaN Double Double.NaN {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} double sign = 1; sign 1 int b = input.read(); b input.read() input.read input while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			} (b < '0' || '9' < b) && b != '-' && b != '+' (b < '0' || '9' < b) && b != '-' && b != '+' (b < '0' || '9' < b) b < '0' b '0' '9' < b '9' b b != '-' b '-' b != '+' b '+' {
				b = input.read();
			} b = input.read() b input.read() input.read input if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			} b == '-' b '-' {
				sign = -1;
				b = input.read();
			} sign = -1 sign -1 1 b = input.read() b input.read() input.read input if (b == '+') {
				b = input.read();
			} b == '+' b '+' {
				b = input.read();
			} b = input.read() b input.read() input.read input double ret = b - '0'; ret b - '0' b '0' while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			} true {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			} b = input.read() b input.read() input.read input if (b < '0' || '9' < b) break; b < '0' || '9' < b b < '0' b '0' '9' < b '9' b break; ret *= 10 ret 10 ret += b - '0' ret b - '0' b '0' if (b != '.') return sign * ret; b != '.' b '.' return sign * ret; sign * ret sign ret double div = 1; div 1 b = input.read() b input.read() input.read input while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			} '0' <= b && b <= '9' '0' <= b '0' b b <= '9' b '9' {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			} ret *= 10 ret 10 ret += b - '0' ret b - '0' b '0' div *= 10 div 10 b = input.read() b input.read() input.read input return sign * ret / div; sign * ret / div sign * ret sign ret div char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	} nextChar {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	} try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		} IOException e {
			e.printStackTrace();
			return 0;
		} e.printStackTrace() e.printStackTrace e return 0; 0 {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} int b = input.read(); b input.read() input.read input while (Character.isWhitespace(b)) {
				b = input.read();
			} Character.isWhitespace(b) Character.isWhitespace Character b {
				b = input.read();
			} b = input.read() b input.read() input.read input return (char) b; (char) b String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	} nextStr {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	} try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		} IOException e {
			e.printStackTrace();
			return "";
		} e.printStackTrace() e.printStackTrace e return ""; "" {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} StringBuilder sb = new StringBuilder(); sb new StringBuilder() int b = input.read(); b input.read() input.read input while (Character.isWhitespace(b)) {
				b = input.read();
			} Character.isWhitespace(b) Character.isWhitespace Character b {
				b = input.read();
			} b = input.read() b input.read() input.read input while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			} b != -1 && !Character.isWhitespace(b) b != -1 b -1 1 !Character.isWhitespace(b) Character.isWhitespace(b) Character.isWhitespace Character b {
				sb.append((char) b);
				b = input.read();
			} sb.append((char) b) sb.append sb (char) b b = input.read() b input.read() input.read input return sb.toString(); sb.toString() sb.toString sb public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	long A, B, C, D;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		A = in.nextLong(); B = in.nextLong(); C = in.nextLong(); D = in.nextLong();
		out.println((f(B) - f(A-1)));
	}
	
	long f(long X){
		return X - (X / C + X / D - X / (lcm(C, D)));
	}
	
	long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	
	long lcm(long a, long b){
		return a / gcd(a, b) * b; //オーバーフローに注意
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
} public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	long A, B, C, D;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		A = in.nextLong(); B = in.nextLong(); C = in.nextLong(); D = in.nextLong();
		out.println((f(B) - f(A-1)));
	}
	
	long f(long X){
		return X - (X / C + X / D - X / (lcm(C, D)));
	}
	
	long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	
	long lcm(long a, long b){
		return a / gcd(a, b) * b; //オーバーフローに注意
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
} Main
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	long A, B, C, D;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		A = in.nextLong(); B = in.nextLong(); C = in.nextLong(); D = in.nextLong();
		out.println((f(B) - f(A-1)));
	}
	
	long f(long X){
		return X - (X / C + X / D - X / (lcm(C, D)));
	}
	
	long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	
	long lcm(long a, long b){
		return a / gcd(a, b) * b; //オーバーフローに注意
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}