

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();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long cd = gcd(c, d);

		long cdd = c / cd * d;

		long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd;

		if (a % c == 0)
			e++;
		if (a % d == 0)
			e++;
		if (a % cdd == 0)
			e--;

		System.out.println(b - a + 1 - e);

	}

	static long gcd(long l, long m) {
		long n = l;
		if (l < m) {
			l = m;
			m = n;
		}

		while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		}

		return l;
	}

} 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();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long cd = gcd(c, d);

		long cdd = c / cd * d;

		long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd;

		if (a % c == 0)
			e++;
		if (a % d == 0)
			e++;
		if (a % cdd == 0)
			e--;

		System.out.println(b - a + 1 - e);

	}

	static long gcd(long l, long m) {
		long n = l;
		if (l < m) {
			l = m;
			m = n;
		}

		while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		}

		return l;
	}

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

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long cd = gcd(c, d);

		long cdd = c / cd * d;

		long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd;

		if (a % c == 0)
			e++;
		if (a % d == 0)
			e++;
		if (a % cdd == 0)
			e--;

		System.out.println(b - a + 1 - e);

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

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long cd = gcd(c, d);

		long cdd = c / cd * d;

		long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd;

		if (a % c == 0)
			e++;
		if (a % d == 0)
			e++;
		if (a % cdd == 0)
			e--;

		System.out.println(b - a + 1 - e);

	} 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 long c = sc.nextLong(); c sc.nextLong() sc.nextLong sc long d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long cd = gcd(c, d); cd gcd(c, d) gcd c d long cdd = c / cd * d; cdd c / cd * d c / cd c cd d long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd; e b / c - a / c + b / d - a / d - b / cdd + a / cdd b / c - a / c + b / d - a / d - b / cdd b / c - a / c + b / d - a / d - b / cdd b / c - a / c + b / d b / c - a / c b / c b c a / c a c b / d b d a / d a d b / cdd b cdd a / cdd a cdd if (a % c == 0)
			e++; a % c == 0 a % c a c 0 e++ e if (a % d == 0)
			e++; a % d == 0 a % d a d 0 e++ e if (a % cdd == 0)
			e--; a % cdd == 0 a % cdd a cdd 0 e-- e System.out.println(b - a + 1 - e) System.out.println System.out System System.out b - a + 1 - e b - a + 1 b - a b a 1 e String[] args args static long gcd(long l, long m) {
		long n = l;
		if (l < m) {
			l = m;
			m = n;
		}

		while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		}

		return l;
	} gcd {
		long n = l;
		if (l < m) {
			l = m;
			m = n;
		}

		while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		}

		return l;
	} long n = l; n l if (l < m) {
			l = m;
			m = n;
		} l < m l m {
			l = m;
			m = n;
		} l = m l m m = n m n while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		} m != 0 m 0 {
			n = m;
			m = l % m;
			l = n;
		} n = m n m m = l % m m l % m l m l = n l n return l; l long l l long m m public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long cd = gcd(c, d);

		long cdd = c / cd * d;

		long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd;

		if (a % c == 0)
			e++;
		if (a % d == 0)
			e++;
		if (a % cdd == 0)
			e--;

		System.out.println(b - a + 1 - e);

	}

	static long gcd(long l, long m) {
		long n = l;
		if (l < m) {
			l = m;
			m = n;
		}

		while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		}

		return l;
	}

} public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long cd = gcd(c, d);

		long cdd = c / cd * d;

		long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd;

		if (a % c == 0)
			e++;
		if (a % d == 0)
			e++;
		if (a % cdd == 0)
			e--;

		System.out.println(b - a + 1 - e);

	}

	static long gcd(long l, long m) {
		long n = l;
		if (l < m) {
			l = m;
			m = n;
		}

		while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		}

		return l;
	}

} 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();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long cd = gcd(c, d);

		long cdd = c / cd * d;

		long e = b / c - a / c + b / d - a / d - b / cdd + a / cdd;

		if (a % c == 0)
			e++;
		if (a % d == 0)
			e++;
		if (a % cdd == 0)
			e--;

		System.out.println(b - a + 1 - e);

	}

	static long gcd(long l, long m) {
		long n = l;
		if (l < m) {
			l = m;
			m = n;
		}

		while (m != 0) {
			n = m;
			m = l % m;
			l = n;
		}

		return l;
	}

}
