import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long ans = 0;
		long countc = 0;
		long countd = 0;
		long countlcm = 0;
		long gcd = 0;
		long lcm = 0;

		long tmpc = c;
		long tmpd = d;

		if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		}

		long r = 0;
		while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		}

		lcm = (long) c * d / tmpc;

		countc = b / c - a / c;
		if (a % c == 0) {
			countc++;
		}
		countd = b / d - a / d;
		if (a % d == 0) {
			countd++;
		}
		countlcm = b / lcm - a / lcm;
		if (a % lcm == 0) {
			countlcm++;
		}
		ans = b - a + 1 - (countc + countd - countlcm);

		System.out.println(ans);

		//		System.out.println(countc);
		//		System.out.println(countd);
		//		System.out.println(countlcm);

	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long ans = 0;
		long countc = 0;
		long countd = 0;
		long countlcm = 0;
		long gcd = 0;
		long lcm = 0;

		long tmpc = c;
		long tmpd = d;

		if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		}

		long r = 0;
		while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		}

		lcm = (long) c * d / tmpc;

		countc = b / c - a / c;
		if (a % c == 0) {
			countc++;
		}
		countd = b / d - a / d;
		if (a % d == 0) {
			countd++;
		}
		countlcm = b / lcm - a / lcm;
		if (a % lcm == 0) {
			countlcm++;
		}
		ans = b - a + 1 - (countc + countd - countlcm);

		System.out.println(ans);

		//		System.out.println(countc);
		//		System.out.println(countd);
		//		System.out.println(countlcm);

	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long ans = 0;
		long countc = 0;
		long countd = 0;
		long countlcm = 0;
		long gcd = 0;
		long lcm = 0;

		long tmpc = c;
		long tmpd = d;

		if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		}

		long r = 0;
		while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		}

		lcm = (long) c * d / tmpc;

		countc = b / c - a / c;
		if (a % c == 0) {
			countc++;
		}
		countd = b / d - a / d;
		if (a % d == 0) {
			countd++;
		}
		countlcm = b / lcm - a / lcm;
		if (a % lcm == 0) {
			countlcm++;
		}
		ans = b - a + 1 - (countc + countd - countlcm);

		System.out.println(ans);

		//		System.out.println(countc);
		//		System.out.println(countd);
		//		System.out.println(countlcm);

	} main {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long ans = 0;
		long countc = 0;
		long countd = 0;
		long countlcm = 0;
		long gcd = 0;
		long lcm = 0;

		long tmpc = c;
		long tmpd = d;

		if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		}

		long r = 0;
		while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		}

		lcm = (long) c * d / tmpc;

		countc = b / c - a / c;
		if (a % c == 0) {
			countc++;
		}
		countd = b / d - a / d;
		if (a % d == 0) {
			countd++;
		}
		countlcm = b / lcm - a / lcm;
		if (a % lcm == 0) {
			countlcm++;
		}
		ans = b - a + 1 - (countc + countd - countlcm);

		System.out.println(ans);

		//		System.out.println(countc);
		//		System.out.println(countd);
		//		System.out.println(countlcm);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong(); a sc.nextLong() sc.nextLong sc long b = sc.nextLong(); b sc.nextLong() sc.nextLong sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc long ans = 0; ans 0 long countc = 0; countc 0 long countd = 0; countd 0 long countlcm = 0; countlcm 0 long gcd = 0; gcd 0 long lcm = 0; lcm 0 long tmpc = c; tmpc c long tmpd = d; tmpd d if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		} d > c d c {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		} long tmp = tmpd; tmp tmpd tmpd = tmpc tmpd tmpc tmpc = tmp tmpc tmp long r = 0; r 0 while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		} tmpd > 0 tmpd 0 {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		} r = tmpc % tmpd r tmpc % tmpd tmpc tmpd tmpc = tmpd tmpc tmpd tmpd = r tmpd r lcm = (long) c * d / tmpc lcm (long) c * d / tmpc (long) c * d (long) c d tmpc countc = b / c - a / c countc b / c - a / c b / c b c a / c a c if (a % c == 0) {
			countc++;
		} a % c == 0 a % c a c 0 {
			countc++;
		} countc++ countc countd = b / d - a / d countd b / d - a / d b / d b d a / d a d if (a % d == 0) {
			countd++;
		} a % d == 0 a % d a d 0 {
			countd++;
		} countd++ countd countlcm = b / lcm - a / lcm countlcm b / lcm - a / lcm b / lcm b lcm a / lcm a lcm if (a % lcm == 0) {
			countlcm++;
		} a % lcm == 0 a % lcm a lcm 0 {
			countlcm++;
		} countlcm++ countlcm ans = b - a + 1 - (countc + countd - countlcm) ans b - a + 1 - (countc + countd - countlcm) b - a + 1 b - a b a 1 (countc + countd - countlcm) countc + countd countc countd countlcm System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long ans = 0;
		long countc = 0;
		long countd = 0;
		long countlcm = 0;
		long gcd = 0;
		long lcm = 0;

		long tmpc = c;
		long tmpd = d;

		if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		}

		long r = 0;
		while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		}

		lcm = (long) c * d / tmpc;

		countc = b / c - a / c;
		if (a % c == 0) {
			countc++;
		}
		countd = b / d - a / d;
		if (a % d == 0) {
			countd++;
		}
		countlcm = b / lcm - a / lcm;
		if (a % lcm == 0) {
			countlcm++;
		}
		ans = b - a + 1 - (countc + countd - countlcm);

		System.out.println(ans);

		//		System.out.println(countc);
		//		System.out.println(countd);
		//		System.out.println(countlcm);

	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long ans = 0;
		long countc = 0;
		long countd = 0;
		long countlcm = 0;
		long gcd = 0;
		long lcm = 0;

		long tmpc = c;
		long tmpd = d;

		if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		}

		long r = 0;
		while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		}

		lcm = (long) c * d / tmpc;

		countc = b / c - a / c;
		if (a % c == 0) {
			countc++;
		}
		countd = b / d - a / d;
		if (a % d == 0) {
			countd++;
		}
		countlcm = b / lcm - a / lcm;
		if (a % lcm == 0) {
			countlcm++;
		}
		ans = b - a + 1 - (countc + countd - countlcm);

		System.out.println(ans);

		//		System.out.println(countc);
		//		System.out.println(countd);
		//		System.out.println(countlcm);

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long ans = 0;
		long countc = 0;
		long countd = 0;
		long countlcm = 0;
		long gcd = 0;
		long lcm = 0;

		long tmpc = c;
		long tmpd = d;

		if (d > c) {
			long tmp = tmpd;
			tmpd = tmpc;
			tmpc = tmp;
		}

		long r = 0;
		while (tmpd > 0) {
			r = tmpc % tmpd;
			tmpc = tmpd;
			tmpd = r;
		}

		lcm = (long) c * d / tmpc;

		countc = b / c - a / c;
		if (a % c == 0) {
			countc++;
		}
		countd = b / d - a / d;
		if (a % d == 0) {
			countd++;
		}
		countlcm = b / lcm - a / lcm;
		if (a % lcm == 0) {
			countlcm++;
		}
		ans = b - a + 1 - (countc + countd - countlcm);

		System.out.println(ans);

		//		System.out.println(countc);
		//		System.out.println(countd);
		//		System.out.println(countlcm);

	}
}