import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		}
	}

	static long lcm (long a,long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		}
	}

	static long lcm (long a,long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
} Main public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		}
	} main {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		}
	} try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		} {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		} Scanner scn = new Scanner(System.in) Scanner scn = new Scanner(System.in) new Scanner(System.in) long A = scn.nextLong(); A scn.nextLong() scn.nextLong scn long B = scn.nextLong(); B scn.nextLong() scn.nextLong scn long C = scn.nextLong(); C scn.nextLong() scn.nextLong scn long D = scn.nextLong(); D scn.nextLong() scn.nextLong scn long minmaxVal = B - A + 1; minmaxVal B - A + 1 B - A B A 1 long cd = lcm(C, D); cd lcm(C, D) lcm C D long div = B / cd - ((A - 1) / cd); div B / cd - ((A - 1) / cd) B / cd B cd ((A - 1) / cd) (A - 1) A 1 cd long cDiv = (A - 1) / C - B / C; cDiv (A - 1) / C - B / C (A - 1) / C (A - 1) A 1 C B / C B C long dDiv = (A - 1) / D - B / D; dDiv (A - 1) / D - B / D (A - 1) / D (A - 1) A 1 D B / D B D System.out.println(minmaxVal + div + cDiv + dDiv) System.out.println System.out System System.out minmaxVal + div + cDiv + dDiv cDiv minmaxVal + div + cDiv + dDiv minmaxVal div cDiv dDiv String[] args args static long lcm (long a,long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	} lcm {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	} long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
			a = b;
			b = temp;
		} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
			a = b;
			b = temp;
		} a = b a b b = temp b temp return c/b; c/b c b long a a long b b public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		}
	}

	static long lcm (long a,long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
} public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		}
	}

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

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long C = scn.nextLong();
			long D = scn.nextLong();

			long minmaxVal = B - A + 1;
			long cd = lcm(C, D);
			long div = B / cd - ((A - 1) / cd);
			long cDiv = (A - 1) / C - B / C;
			long dDiv = (A - 1) / D - B / D;

			System.out.println(minmaxVal + div + cDiv + dDiv);

		}
	}

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