import java.math.BigInteger;
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = new BigInteger(sc.next());
		BigInteger B = new BigInteger(sc.next());
		BigInteger C = new BigInteger(sc.next());
		BigInteger D = new BigInteger(sc.next());

		BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める

		//Cの約数の個数
		BigInteger c_y = yakusuu(A,B,C) ;

		//Dの約数の個数
		BigInteger d_y = yakusuu(A,B,D) ;

		//C*Dの約数の個数
		BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ;

		//答え
		BigInteger count = B.subtract(A).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める
		BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ;

		System.out.println(ans.toString(10));
	}

	private BigInteger yakusuu(BigInteger start, BigInteger end, BigInteger num) {
		if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		}
		if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		}

		BigInteger top ;

		if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		}

		BigInteger last ;
		if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		}

		BigInteger top_count = top.divide(num) ;
		BigInteger last_count = last.divide(num) ;

		BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ;


		return count ;
	}

	private BigInteger lcm(BigInteger m, BigInteger n) {
	    return m.multiply(n).divide(gcd(m, n));
	}
	private BigInteger gcd(BigInteger m, BigInteger n) {
	    if(m.compareTo(n) < 0) return gcd(n, m);
	    if(n.equals(BigInteger.ZERO)) return m;
	    return gcd(n, m.mod(n));
	}
} import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = new BigInteger(sc.next());
		BigInteger B = new BigInteger(sc.next());
		BigInteger C = new BigInteger(sc.next());
		BigInteger D = new BigInteger(sc.next());

		BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める

		//Cの約数の個数
		BigInteger c_y = yakusuu(A,B,C) ;

		//Dの約数の個数
		BigInteger d_y = yakusuu(A,B,D) ;

		//C*Dの約数の個数
		BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ;

		//答え
		BigInteger count = B.subtract(A).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める
		BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ;

		System.out.println(ans.toString(10));
	}

	private BigInteger yakusuu(BigInteger start, BigInteger end, BigInteger num) {
		if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		}
		if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		}

		BigInteger top ;

		if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		}

		BigInteger last ;
		if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		}

		BigInteger top_count = top.divide(num) ;
		BigInteger last_count = last.divide(num) ;

		BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ;


		return count ;
	}

	private BigInteger lcm(BigInteger m, BigInteger n) {
	    return m.multiply(n).divide(gcd(m, n));
	}
	private BigInteger gcd(BigInteger m, BigInteger n) {
	    if(m.compareTo(n) < 0) return gcd(n, m);
	    if(n.equals(BigInteger.ZERO)) return m;
	    return gcd(n, m.mod(n));
	}
} Main public static void main(String[] args) {
		(new Main()).execute();
	} main {
		(new Main()).execute();
	} (new Main()).execute() (new Main()).execute (new Main()) String[] args args public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = new BigInteger(sc.next());
		BigInteger B = new BigInteger(sc.next());
		BigInteger C = new BigInteger(sc.next());
		BigInteger D = new BigInteger(sc.next());

		BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める

		//Cの約数の個数
		BigInteger c_y = yakusuu(A,B,C) ;

		//Dの約数の個数
		BigInteger d_y = yakusuu(A,B,D) ;

		//C*Dの約数の個数
		BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ;

		//答え
		BigInteger count = B.subtract(A).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める
		BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ;

		System.out.println(ans.toString(10));
	} execute { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = new BigInteger(sc.next());
		BigInteger B = new BigInteger(sc.next());
		BigInteger C = new BigInteger(sc.next());
		BigInteger D = new BigInteger(sc.next());

		BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める

		//Cの約数の個数
		BigInteger c_y = yakusuu(A,B,C) ;

		//Dの約数の個数
		BigInteger d_y = yakusuu(A,B,D) ;

		//C*Dの約数の個数
		BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ;

		//答え
		BigInteger count = B.subtract(A).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める
		BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ;

		System.out.println(ans.toString(10));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) BigInteger A = new BigInteger(sc.next()); A new BigInteger(sc.next()) BigInteger B = new BigInteger(sc.next()); B new BigInteger(sc.next()) BigInteger C = new BigInteger(sc.next()); C new BigInteger(sc.next()) BigInteger D = new BigInteger(sc.next()); D new BigInteger(sc.next()) BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE); B_A B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE) B.add(A.multiply(new BigInteger("-1"))).add B.add(A.multiply(new BigInteger("-1"))) B.add B A.multiply(new BigInteger("-1")) A.multiply A new BigInteger("-1") BigInteger.ONE BigInteger BigInteger.ONE BigInteger c_y = yakusuu(A,B,C) ; c_y yakusuu(A,B,C) yakusuu A B C BigInteger d_y = yakusuu(A,B,D) ; d_y yakusuu(A,B,D) yakusuu A B D BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ; cd_y yakusuu(A,B,lcm(C,D)) yakusuu A B lcm(C,D) lcm C D BigInteger count = B.subtract(A).add(BigInteger.ONE); count B.subtract(A).add(BigInteger.ONE) B.subtract(A).add B.subtract(A) B.subtract B A BigInteger.ONE BigInteger BigInteger.ONE BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ; ans count.subtract(c_y).subtract(d_y).add(cd_y) count.subtract(c_y).subtract(d_y).add count.subtract(c_y).subtract(d_y) count.subtract(c_y).subtract count.subtract(c_y) count.subtract count c_y d_y cd_y System.out.println(ans.toString(10)) System.out.println System.out System System.out ans.toString(10) ans.toString ans 10 private BigInteger yakusuu(BigInteger start, BigInteger end, BigInteger num) {
		if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		}
		if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		}

		BigInteger top ;

		if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		}

		BigInteger last ;
		if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		}

		BigInteger top_count = top.divide(num) ;
		BigInteger last_count = last.divide(num) ;

		BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ;


		return count ;
	} yakusuu {
		if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		}
		if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		}

		BigInteger top ;

		if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		}

		BigInteger last ;
		if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		}

		BigInteger top_count = top.divide(num) ;
		BigInteger last_count = last.divide(num) ;

		BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ;


		return count ;
	} if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		} 0 < num.compareTo(end) 0 num.compareTo(end) num.compareTo num end {
			return BigInteger.ZERO ;
		} return BigInteger.ZERO ; BigInteger.ZERO BigInteger BigInteger.ZERO if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		} num.compareTo(end) == 0 num.compareTo(end) num.compareTo num end 0 {
			return BigInteger.ONE ;
		} return BigInteger.ONE ; BigInteger.ONE BigInteger BigInteger.ONE BigInteger top ; top if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		} start.mod(num).equals(BigInteger.ZERO) start.mod(num).equals start.mod(num) start.mod start num BigInteger.ZERO BigInteger BigInteger.ZERO {
			top = start ;
		} top = start top start {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		} top = num.multiply(start.divide(num).add(BigInteger.ONE)) top num.multiply(start.divide(num).add(BigInteger.ONE)) num.multiply num start.divide(num).add(BigInteger.ONE) start.divide(num).add start.divide(num) start.divide start num BigInteger.ONE BigInteger BigInteger.ONE BigInteger last ; last if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		} end.mod(num).equals(BigInteger.ZERO) end.mod(num).equals end.mod(num) end.mod end num BigInteger.ZERO BigInteger BigInteger.ZERO {
			last = end ;
		} last = end last end {
			last = num.multiply(end.divide(num)) ;
		} last = num.multiply(end.divide(num)) last num.multiply(end.divide(num)) num.multiply num end.divide(num) end.divide end num BigInteger top_count = top.divide(num) ; top_count top.divide(num) top.divide top num BigInteger last_count = last.divide(num) ; last_count last.divide(num) last.divide last num BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ; count last_count.subtract(top_count.subtract(BigInteger.ONE)) last_count.subtract last_count top_count.subtract(BigInteger.ONE) top_count.subtract top_count BigInteger.ONE BigInteger BigInteger.ONE return count ; count BigInteger start start BigInteger end end BigInteger num num private BigInteger lcm(BigInteger m, BigInteger n) {
	    return m.multiply(n).divide(gcd(m, n));
	} lcm {
	    return m.multiply(n).divide(gcd(m, n));
	} return m.multiply(n).divide(gcd(m, n)); m.multiply(n).divide(gcd(m, n)) m.multiply(n).divide m.multiply(n) m.multiply m n gcd(m, n) gcd m n BigInteger m m BigInteger n n private BigInteger gcd(BigInteger m, BigInteger n) {
	    if(m.compareTo(n) < 0) return gcd(n, m);
	    if(n.equals(BigInteger.ZERO)) return m;
	    return gcd(n, m.mod(n));
	} gcd {
	    if(m.compareTo(n) < 0) return gcd(n, m);
	    if(n.equals(BigInteger.ZERO)) return m;
	    return gcd(n, m.mod(n));
	} if(m.compareTo(n) < 0) return gcd(n, m); m.compareTo(n) < 0 m.compareTo(n) m.compareTo m n 0 return gcd(n, m); gcd(n, m) gcd n m if(n.equals(BigInteger.ZERO)) return m; n.equals(BigInteger.ZERO) n.equals n BigInteger.ZERO BigInteger BigInteger.ZERO return m; m return gcd(n, m.mod(n)); gcd(n, m.mod(n)) gcd n m.mod(n) m.mod m n BigInteger m m BigInteger n n public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = new BigInteger(sc.next());
		BigInteger B = new BigInteger(sc.next());
		BigInteger C = new BigInteger(sc.next());
		BigInteger D = new BigInteger(sc.next());

		BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める

		//Cの約数の個数
		BigInteger c_y = yakusuu(A,B,C) ;

		//Dの約数の個数
		BigInteger d_y = yakusuu(A,B,D) ;

		//C*Dの約数の個数
		BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ;

		//答え
		BigInteger count = B.subtract(A).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める
		BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ;

		System.out.println(ans.toString(10));
	}

	private BigInteger yakusuu(BigInteger start, BigInteger end, BigInteger num) {
		if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		}
		if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		}

		BigInteger top ;

		if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		}

		BigInteger last ;
		if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		}

		BigInteger top_count = top.divide(num) ;
		BigInteger last_count = last.divide(num) ;

		BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ;


		return count ;
	}

	private BigInteger lcm(BigInteger m, BigInteger n) {
	    return m.multiply(n).divide(gcd(m, n));
	}
	private BigInteger gcd(BigInteger m, BigInteger n) {
	    if(m.compareTo(n) < 0) return gcd(n, m);
	    if(n.equals(BigInteger.ZERO)) return m;
	    return gcd(n, m.mod(n));
	}
} public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = new BigInteger(sc.next());
		BigInteger B = new BigInteger(sc.next());
		BigInteger C = new BigInteger(sc.next());
		BigInteger D = new BigInteger(sc.next());

		BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める

		//Cの約数の個数
		BigInteger c_y = yakusuu(A,B,C) ;

		//Dの約数の個数
		BigInteger d_y = yakusuu(A,B,D) ;

		//C*Dの約数の個数
		BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ;

		//答え
		BigInteger count = B.subtract(A).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める
		BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ;

		System.out.println(ans.toString(10));
	}

	private BigInteger yakusuu(BigInteger start, BigInteger end, BigInteger num) {
		if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		}
		if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		}

		BigInteger top ;

		if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		}

		BigInteger last ;
		if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		}

		BigInteger top_count = top.divide(num) ;
		BigInteger last_count = last.divide(num) ;

		BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ;


		return count ;
	}

	private BigInteger lcm(BigInteger m, BigInteger n) {
	    return m.multiply(n).divide(gcd(m, n));
	}
	private BigInteger gcd(BigInteger m, BigInteger n) {
	    if(m.compareTo(n) < 0) return gcd(n, m);
	    if(n.equals(BigInteger.ZERO)) return m;
	    return gcd(n, m.mod(n));
	}
} Main
import java.math.BigInteger;
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = new BigInteger(sc.next());
		BigInteger B = new BigInteger(sc.next());
		BigInteger C = new BigInteger(sc.next());
		BigInteger D = new BigInteger(sc.next());

		BigInteger B_A = B.add(A.multiply(new BigInteger("-1"))).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める

		//Cの約数の個数
		BigInteger c_y = yakusuu(A,B,C) ;

		//Dの約数の個数
		BigInteger d_y = yakusuu(A,B,D) ;

		//C*Dの約数の個数
		BigInteger cd_y = yakusuu(A,B,lcm(C,D)) ;

		//答え
		BigInteger count = B.subtract(A).add(BigInteger.ONE);//A～Bまでの個数（B-A + 1）を求める
		BigInteger ans = count.subtract(c_y).subtract(d_y).add(cd_y) ;

		System.out.println(ans.toString(10));
	}

	private BigInteger yakusuu(BigInteger start, BigInteger end, BigInteger num) {
		if(0 < num.compareTo(end)) {
			return BigInteger.ZERO ;
		}
		if(num.compareTo(end) == 0) {
			return BigInteger.ONE ;
		}

		BigInteger top ;

		if(start.mod(num).equals(BigInteger.ZERO)) {
			top = start ;
		}else {
			top = num.multiply(start.divide(num).add(BigInteger.ONE)) ;
		}

		BigInteger last ;
		if(end.mod(num).equals(BigInteger.ZERO)) {
			last = end ;
		}else {
			last = num.multiply(end.divide(num)) ;
		}

		BigInteger top_count = top.divide(num) ;
		BigInteger last_count = last.divide(num) ;

		BigInteger count = last_count.subtract(top_count.subtract(BigInteger.ONE)) ;


		return count ;
	}

	private BigInteger lcm(BigInteger m, BigInteger n) {
	    return m.multiply(n).divide(gcd(m, n));
	}
	private BigInteger gcd(BigInteger m, BigInteger n) {
	    if(m.compareTo(n) < 0) return gcd(n, m);
	    if(n.equals(BigInteger.ZERO)) return m;
	    return gcd(n, m.mod(n));
	}
}
