import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

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

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	} main {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	} Scanner s = new Scanner(System.in); s new Scanner(System.in) long A = s.nextLong(); A s.nextLong() s.nextLong s long B = s.nextLong(); B s.nextLong() s.nextLong s long C = s.nextLong(); C s.nextLong() s.nextLong s long D = s.nextLong(); D s.nextLong() s.nextLong s long cBai = B/C - (A-1)/C; cBai B/C - (A-1)/C B/C B C (A-1)/C (A-1) A 1 C long dBai = B/D - (A-1)/D; dBai B/D - (A-1)/D B/D B D (A-1)/D (A-1) A 1 D long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D); cdBai B/(lcm(C,D)) - (A-1)/lcm(C,D) B/(lcm(C,D)) B (lcm(C,D)) lcm C D (A-1)/lcm(C,D) (A-1) A 1 lcm(C,D) lcm C D long answer = (B - (A-1) - (cBai + dBai - cdBai)); answer (B - (A-1) - (cBai + dBai - cdBai)) B - (A-1) - (cBai + dBai - cdBai) B (A-1) A 1 (cBai + dBai - cdBai) cBai + dBai cBai dBai cdBai System.out.println(answer) System.out.println System.out System System.out answer String[] args args private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	} lcm {
	    return m * n / gcd(m, n);
	} return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	} gcd {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	} if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long A = s.nextLong();
		long B = s.nextLong();
		long C = s.nextLong();
		long D = s.nextLong();

		/*
		long count = 0;
		for (long i = A; i <= B; i++) {

			if(i % C ==0) continue;
			if(i % D ==0) continue;
			count++;
		}

		System.out.println(count);
		*/

		//Cの倍数の個数
		long cBai = B/C - (A-1)/C;
		//Dの倍数の個数
		long dBai = B/D - (A-1)/D;
		//CとDの倍数の個数
		long cdBai = B/(lcm(C,D)) - (A-1)/lcm(C,D);
		//全体から引く
		long answer = (B - (A-1) - (cBai + dBai - cdBai));

		System.out.println(answer);

	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}
