import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong() - 1;
		long B = scan.nextLong();
		long C = scan.nextLong();
		long D = scan.nextLong();

		long tmp = (C * D) / gcd(C, D);
		long n = ((B - (B / C + B / D)) + (B / tmp));
		long m = ((A - (A / C + A / D)) + (A / tmp));

		System.out.println(n - m);
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		a = a % b;
		return gcd(b, a);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong() - 1;
		long B = scan.nextLong();
		long C = scan.nextLong();
		long D = scan.nextLong();

		long tmp = (C * D) / gcd(C, D);
		long n = ((B - (B / C + B / D)) + (B / tmp));
		long m = ((A - (A / C + A / D)) + (A / tmp));

		System.out.println(n - m);
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		a = a % b;
		return gcd(b, a);
	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong() - 1;
		long B = scan.nextLong();
		long C = scan.nextLong();
		long D = scan.nextLong();

		long tmp = (C * D) / gcd(C, D);
		long n = ((B - (B / C + B / D)) + (B / tmp));
		long m = ((A - (A / C + A / D)) + (A / tmp));

		System.out.println(n - m);
	} main {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong() - 1;
		long B = scan.nextLong();
		long C = scan.nextLong();
		long D = scan.nextLong();

		long tmp = (C * D) / gcd(C, D);
		long n = ((B - (B / C + B / D)) + (B / tmp));
		long m = ((A - (A / C + A / D)) + (A / tmp));

		System.out.println(n - m);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long A = scan.nextLong() - 1; A scan.nextLong() - 1 scan.nextLong() scan.nextLong scan 1 long B = scan.nextLong(); B scan.nextLong() scan.nextLong scan long C = scan.nextLong(); C scan.nextLong() scan.nextLong scan long D = scan.nextLong(); D scan.nextLong() scan.nextLong scan long tmp = (C * D) / gcd(C, D); tmp (C * D) / gcd(C, D) (C * D) C D gcd(C, D) gcd C D long n = ((B - (B / C + B / D)) + (B / tmp)); n ((B - (B / C + B / D)) + (B / tmp)) (B - (B / C + B / D)) B (B / C + B / D) B / C B C B / D B D (B / tmp) B tmp long m = ((A - (A / C + A / D)) + (A / tmp)); m ((A - (A / C + A / D)) + (A / tmp)) (A - (A / C + A / D)) A (A / C + A / D) A / C A C A / D A D (A / tmp) A tmp System.out.println(n - m) System.out.println System.out System System.out n - m n m String[] args args static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		a = a % b;
		return gcd(b, a);
	} gcd {
		if (b == 0) {
			return a;
		}
		a = a % b;
		return gcd(b, a);
	} if (b == 0) {
			return a;
		} b == 0 b 0 {
			return a;
		} return a; a a = a % b a a % b a b return gcd(b, a); gcd(b, a) gcd b a long a a long b b public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong() - 1;
		long B = scan.nextLong();
		long C = scan.nextLong();
		long D = scan.nextLong();

		long tmp = (C * D) / gcd(C, D);
		long n = ((B - (B / C + B / D)) + (B / tmp));
		long m = ((A - (A / C + A / D)) + (A / tmp));

		System.out.println(n - m);
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		a = a % b;
		return gcd(b, a);
	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong() - 1;
		long B = scan.nextLong();
		long C = scan.nextLong();
		long D = scan.nextLong();

		long tmp = (C * D) / gcd(C, D);
		long n = ((B - (B / C + B / D)) + (B / tmp));
		long m = ((A - (A / C + A / D)) + (A / tmp));

		System.out.println(n - m);
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		a = a % b;
		return gcd(b, a);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong() - 1;
		long B = scan.nextLong();
		long C = scan.nextLong();
		long D = scan.nextLong();

		long tmp = (C * D) / gcd(C, D);
		long n = ((B - (B / C + B / D)) + (B / tmp));
		long m = ((A - (A / C + A / D)) + (A / tmp));

		System.out.println(n - m);
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		a = a % b;
		return gcd(b, a);
	}
}