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

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()));

	}

	public static BigInteger calc(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE);
		return zenKosu.subtract(calcBiasuKosu(a, b, c, d));
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger cKosu = calcBiasuKosu(a, b, c);
		BigInteger dKosu = calcBiasuKosu(a, b, d);
		BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d));
		return cKosu.add(dKosu).subtract(cdKosu);
	}

	public static BigInteger calcKoBaisu(BigInteger x, BigInteger y) {
		BigInteger a = x;
		BigInteger b = y;
		BigInteger mult = x.multiply(y);
		if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		}
		BigInteger r = a.mod(b);
		while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		}
		return mult.divide(b);
	}

	public static BigInteger calcBiasuKosuFrom1(BigInteger n, BigInteger to) {
		return n.divide(to);
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger n) {
		BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n));
		if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		}
		return res;
	}
} import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()));

	}

	public static BigInteger calc(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE);
		return zenKosu.subtract(calcBiasuKosu(a, b, c, d));
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger cKosu = calcBiasuKosu(a, b, c);
		BigInteger dKosu = calcBiasuKosu(a, b, d);
		BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d));
		return cKosu.add(dKosu).subtract(cdKosu);
	}

	public static BigInteger calcKoBaisu(BigInteger x, BigInteger y) {
		BigInteger a = x;
		BigInteger b = y;
		BigInteger mult = x.multiply(y);
		if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		}
		BigInteger r = a.mod(b);
		while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		}
		return mult.divide(b);
	}

	public static BigInteger calcBiasuKosuFrom1(BigInteger n, BigInteger to) {
		return n.divide(to);
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger n) {
		BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n));
		if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		}
		return res;
	}
} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()));

	} main {
		Scanner s = new Scanner(System.in);
		System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()));

	} Scanner s = new Scanner(System.in); s new Scanner(System.in) System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger())) System.out.println System.out System System.out calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()) calc s.nextBigInteger() s.nextBigInteger s s.nextBigInteger() s.nextBigInteger s s.nextBigInteger() s.nextBigInteger s s.nextBigInteger() s.nextBigInteger s String[] args args public static BigInteger calc(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE);
		return zenKosu.subtract(calcBiasuKosu(a, b, c, d));
	} calc {
		BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE);
		return zenKosu.subtract(calcBiasuKosu(a, b, c, d));
	} BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE); zenKosu b.subtract(a).add(BigInteger.ONE) b.subtract(a).add b.subtract(a) b.subtract b a BigInteger.ONE BigInteger BigInteger.ONE return zenKosu.subtract(calcBiasuKosu(a, b, c, d)); zenKosu.subtract(calcBiasuKosu(a, b, c, d)) zenKosu.subtract zenKosu calcBiasuKosu(a, b, c, d) calcBiasuKosu a b c d BigInteger a a BigInteger b b BigInteger c c BigInteger d d public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger cKosu = calcBiasuKosu(a, b, c);
		BigInteger dKosu = calcBiasuKosu(a, b, d);
		BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d));
		return cKosu.add(dKosu).subtract(cdKosu);
	} calcBiasuKosu {
		BigInteger cKosu = calcBiasuKosu(a, b, c);
		BigInteger dKosu = calcBiasuKosu(a, b, d);
		BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d));
		return cKosu.add(dKosu).subtract(cdKosu);
	} BigInteger cKosu = calcBiasuKosu(a, b, c); cKosu calcBiasuKosu(a, b, c) calcBiasuKosu a b c BigInteger dKosu = calcBiasuKosu(a, b, d); dKosu calcBiasuKosu(a, b, d) calcBiasuKosu a b d BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d)); cdKosu calcBiasuKosu(a, b, calcKoBaisu(c, d)) calcBiasuKosu a b calcKoBaisu(c, d) calcKoBaisu c d return cKosu.add(dKosu).subtract(cdKosu); cKosu.add(dKosu).subtract(cdKosu) cKosu.add(dKosu).subtract cKosu.add(dKosu) cKosu.add cKosu dKosu cdKosu BigInteger a a BigInteger b b BigInteger c c BigInteger d d public static BigInteger calcKoBaisu(BigInteger x, BigInteger y) {
		BigInteger a = x;
		BigInteger b = y;
		BigInteger mult = x.multiply(y);
		if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		}
		BigInteger r = a.mod(b);
		while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		}
		return mult.divide(b);
	} calcKoBaisu {
		BigInteger a = x;
		BigInteger b = y;
		BigInteger mult = x.multiply(y);
		if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		}
		BigInteger r = a.mod(b);
		while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		}
		return mult.divide(b);
	} BigInteger a = x; a x BigInteger b = y; b y BigInteger mult = x.multiply(y); mult x.multiply(y) x.multiply x y if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		} a.compareTo(b) < 0 a.compareTo(b) a.compareTo a b 0 {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		} BigInteger tmp = a; tmp a a = b a b b = tmp b tmp BigInteger r = a.mod(b); r a.mod(b) a.mod a b while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		} !r.equals(BigInteger.ZERO) r.equals(BigInteger.ZERO) r.equals r BigInteger.ZERO BigInteger BigInteger.ZERO {
			a = b;
			b = r;
			r = a.mod(b);
		} a = b a b b = r b r r = a.mod(b) r a.mod(b) a.mod a b return mult.divide(b); mult.divide(b) mult.divide mult b BigInteger x x BigInteger y y public static BigInteger calcBiasuKosuFrom1(BigInteger n, BigInteger to) {
		return n.divide(to);
	} calcBiasuKosuFrom1 {
		return n.divide(to);
	} return n.divide(to); n.divide(to) n.divide n to BigInteger n n BigInteger to to public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger n) {
		BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n));
		if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		}
		return res;
	} calcBiasuKosu {
		BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n));
		if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		}
		return res;
	} BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n)); res calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n)) calcBiasuKosuFrom1(b, n).subtract calcBiasuKosuFrom1(b, n) calcBiasuKosuFrom1 b n calcBiasuKosuFrom1(a, n) calcBiasuKosuFrom1 a n if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		} a.mod(n).equals(BigInteger.ZERO) a.mod(n).equals a.mod(n) a.mod a n BigInteger.ZERO BigInteger BigInteger.ZERO {
			res = res.add(BigInteger.ONE);
		} res = res.add(BigInteger.ONE) res res.add(BigInteger.ONE) res.add res BigInteger.ONE BigInteger BigInteger.ONE return res; res BigInteger a a BigInteger b b BigInteger n n public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()));

	}

	public static BigInteger calc(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE);
		return zenKosu.subtract(calcBiasuKosu(a, b, c, d));
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger cKosu = calcBiasuKosu(a, b, c);
		BigInteger dKosu = calcBiasuKosu(a, b, d);
		BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d));
		return cKosu.add(dKosu).subtract(cdKosu);
	}

	public static BigInteger calcKoBaisu(BigInteger x, BigInteger y) {
		BigInteger a = x;
		BigInteger b = y;
		BigInteger mult = x.multiply(y);
		if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		}
		BigInteger r = a.mod(b);
		while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		}
		return mult.divide(b);
	}

	public static BigInteger calcBiasuKosuFrom1(BigInteger n, BigInteger to) {
		return n.divide(to);
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger n) {
		BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n));
		if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		}
		return res;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()));

	}

	public static BigInteger calc(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE);
		return zenKosu.subtract(calcBiasuKosu(a, b, c, d));
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger cKosu = calcBiasuKosu(a, b, c);
		BigInteger dKosu = calcBiasuKosu(a, b, d);
		BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d));
		return cKosu.add(dKosu).subtract(cdKosu);
	}

	public static BigInteger calcKoBaisu(BigInteger x, BigInteger y) {
		BigInteger a = x;
		BigInteger b = y;
		BigInteger mult = x.multiply(y);
		if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		}
		BigInteger r = a.mod(b);
		while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		}
		return mult.divide(b);
	}

	public static BigInteger calcBiasuKosuFrom1(BigInteger n, BigInteger to) {
		return n.divide(to);
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger n) {
		BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n));
		if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		}
		return res;
	}
} Main
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println(calc(s.nextBigInteger(), s.nextBigInteger(),
				s.nextBigInteger(), s.nextBigInteger()));

	}

	public static BigInteger calc(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger zenKosu = b.subtract(a).add(BigInteger.ONE);
		return zenKosu.subtract(calcBiasuKosu(a, b, c, d));
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger c,
			BigInteger d) {
		BigInteger cKosu = calcBiasuKosu(a, b, c);
		BigInteger dKosu = calcBiasuKosu(a, b, d);
		BigInteger cdKosu = calcBiasuKosu(a, b, calcKoBaisu(c, d));
		return cKosu.add(dKosu).subtract(cdKosu);
	}

	public static BigInteger calcKoBaisu(BigInteger x, BigInteger y) {
		BigInteger a = x;
		BigInteger b = y;
		BigInteger mult = x.multiply(y);
		if (a.compareTo(b) < 0) {
			BigInteger tmp = a;
			a = b;
			b = tmp;
		}
		BigInteger r = a.mod(b);
		while (!r.equals(BigInteger.ZERO)) {
			a = b;
			b = r;
			r = a.mod(b);
		}
		return mult.divide(b);
	}

	public static BigInteger calcBiasuKosuFrom1(BigInteger n, BigInteger to) {
		return n.divide(to);
	}

	public static BigInteger calcBiasuKosu(BigInteger a, BigInteger b, BigInteger n) {
		BigInteger res = calcBiasuKosuFrom1(b, n).subtract(calcBiasuKosuFrom1(a, n));
		if (a.mod(n).equals(BigInteger.ZERO)) {
			res = res.add(BigInteger.ONE);
		}
		return res;
	}
}
