import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	}

	public static long getMaxKoyakusu(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = (long) a % b) != 0) {
			a = b;
			b = (long) temp;
		}
		return (long) (c / b);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	}

	public static long getMaxKoyakusu(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = (long) a % b) != 0) {
			a = b;
			b = (long) temp;
		}
		return (long) (c / b);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	} main {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c = Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d = Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long cBaisuIndex = a / c; cBaisuIndex a / c a c if (a % c != 0) {
			cBaisuIndex++;
		} a % c != 0 a % c a c 0 {
			cBaisuIndex++;
		} cBaisuIndex++ cBaisuIndex long cMaxIndex = b / c + 1; cMaxIndex b / c + 1 b / c b c 1 long dBaisuIndex = a / d; dBaisuIndex a / d a d if (a % d != 0) {
			dBaisuIndex++;
		} a % d != 0 a % d a d 0 {
			dBaisuIndex++;
		} dBaisuIndex++ dBaisuIndex long dMaxIndex = b / d + 1; dMaxIndex b / d + 1 b / d b d 1 long koyakusu = 0; koyakusu 0 koyakusu = getMaxKoyakusu(c, d) koyakusu getMaxKoyakusu(c, d) getMaxKoyakusu c d long cdBaisuIndex = a / koyakusu; cdBaisuIndex a / koyakusu a koyakusu if (a % koyakusu != 0) {
			cdBaisuIndex++;
		} a % koyakusu != 0 a % koyakusu a koyakusu 0 {
			cdBaisuIndex++;
		} cdBaisuIndex++ cdBaisuIndex long cdMaxIndex = b / koyakusu + 1; cdMaxIndex b / koyakusu + 1 b / koyakusu b koyakusu 1 long ab = b - a + 1; ab b - a + 1 b - a b a 1 long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex); ret ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex) ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) ab (cMaxIndex - cBaisuIndex) cMaxIndex cBaisuIndex (dMaxIndex - dBaisuIndex) dMaxIndex dBaisuIndex (cdMaxIndex - cdBaisuIndex) cdMaxIndex cdBaisuIndex System.out.print(ret) System.out.print System.out System System.out ret String[] args args public static long getMaxKoyakusu(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = (long) a % b) != 0) {
			a = b;
			b = (long) temp;
		}
		return (long) (c / b);
	} getMaxKoyakusu {
		long temp;
		long c = a;
		c *= b;
		while ((temp = (long) a % b) != 0) {
			a = b;
			b = (long) temp;
		}
		return (long) (c / b);
	} long temp; temp long c = a; c a c *= b c b while ((temp = (long) a % b) != 0) {
			a = b;
			b = (long) temp;
		} (temp = (long) a % b) != 0 (temp = (long) a % b) temp (long) a % b (long) a b 0 {
			a = b;
			b = (long) temp;
		} a = b a b b = (long) temp b (long) 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) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	}

	public static long getMaxKoyakusu(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = (long) a % b) != 0) {
			a = b;
			b = (long) temp;
		}
		return (long) (c / b);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	}

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