
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long cm = (B / C) - ((A - 1) / C);
		long dm = (B / D) - ((A - 1) / D);
		long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
		long common = (B / lcm) - ((A - 1) / lcm);
		long ans = (B - (A - 1)) - cm - dm + common;
		System.out.println(ans);
		in.close();
	}

	private static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long cm = (B / C) - ((A - 1) / C);
		long dm = (B / D) - ((A - 1) / D);
		long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
		long common = (B / lcm) - ((A - 1) / lcm);
		long ans = (B - (A - 1)) - cm - dm + common;
		System.out.println(ans);
		in.close();
	}

	private static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long cm = (B / C) - ((A - 1) / C);
		long dm = (B / D) - ((A - 1) / D);
		long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
		long common = (B / lcm) - ((A - 1) / lcm);
		long ans = (B - (A - 1)) - cm - dm + common;
		System.out.println(ans);
		in.close();
	} main {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long cm = (B / C) - ((A - 1) / C);
		long dm = (B / D) - ((A - 1) / D);
		long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
		long common = (B / lcm) - ((A - 1) / lcm);
		long ans = (B - (A - 1)) - cm - dm + common;
		System.out.println(ans);
		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) long A = in.nextLong(); A in.nextLong() in.nextLong in long B = in.nextLong(); B in.nextLong() in.nextLong in long C = in.nextLong(); C in.nextLong() in.nextLong in long D = in.nextLong(); D in.nextLong() in.nextLong in long cm = (B / C) - ((A - 1) / C); cm (B / C) - ((A - 1) / C) (B / C) B C ((A - 1) / C) (A - 1) A 1 C long dm = (B / D) - ((A - 1) / D); dm (B / D) - ((A - 1) / D) (B / D) B D ((A - 1) / D) (A - 1) A 1 D long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D)); lcm C * D / gcd(Math.max(C, D), Math.min(C, D)) C * D C D gcd(Math.max(C, D), Math.min(C, D)) gcd Math.max(C, D) Math.max Math C D Math.min(C, D) Math.min Math C D long common = (B / lcm) - ((A - 1) / lcm); common (B / lcm) - ((A - 1) / lcm) (B / lcm) B lcm ((A - 1) / lcm) (A - 1) A 1 lcm long ans = (B - (A - 1)) - cm - dm + common; ans (B - (A - 1)) - cm - dm + common (B - (A - 1)) - cm - dm (B - (A - 1)) - cm - dm (B - (A - 1)) B (A - 1) A 1 cm dm common System.out.println(ans) System.out.println System.out System System.out ans in.close() in.close in String[] args args private static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	} gcd {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	} long temp; temp while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		} m % n != 0 m % n m n 0 {
			temp = n;
			n = m % n;
			m = temp;
		} temp = n temp n n = m % n n m % n m n m = temp m temp return n; n long m m long n n public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long cm = (B / C) - ((A - 1) / C);
		long dm = (B / D) - ((A - 1) / D);
		long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
		long common = (B / lcm) - ((A - 1) / lcm);
		long ans = (B - (A - 1)) - cm - dm + common;
		System.out.println(ans);
		in.close();
	}

	private static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long cm = (B / C) - ((A - 1) / C);
		long dm = (B / D) - ((A - 1) / D);
		long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
		long common = (B / lcm) - ((A - 1) / lcm);
		long ans = (B - (A - 1)) - cm - dm + common;
		System.out.println(ans);
		in.close();
	}

	private static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		long C = in.nextLong();
		long D = in.nextLong();
		long cm = (B / C) - ((A - 1) / C);
		long dm = (B / D) - ((A - 1) / D);
		long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
		long common = (B / lcm) - ((A - 1) / lcm);
		long ans = (B - (A - 1)) - cm - dm + common;
		System.out.println(ans);
		in.close();
	}

	private static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	}
}