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 x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	}

	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 scan = new Scanner(System.in);
		long a = scan.nextLong()-1;
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	}

	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 scan = new Scanner(System.in);
		long a = scan.nextLong()-1;
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	} 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 x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	} 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 x = a - (a / c) - (a / d) + (a / lcm(c, d)); x a - (a / c) - (a / d) + (a / lcm(c, d)) a - (a / c) - (a / d) a - (a / c) - (a / d) a (a / c) a c (a / d) a d (a / lcm(c, d)) a lcm(c, d) lcm c d long y = b - (b / c) - (b / d) + (b / lcm(c, d)); y b - (b / c) - (b / d) + (b / lcm(c, d)) b - (b / c) - (b / d) b - (b / c) - (b / d) b (b / c) b c (b / d) b d (b / lcm(c, d)) b lcm(c, d) lcm c d System.out.println(y-x) System.out.println System.out System System.out y-x y x 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 scan = new Scanner(System.in);
		long a = scan.nextLong()-1;
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	}

	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 scan = new Scanner(System.in);
		long a = scan.nextLong()-1;
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	}

	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 scan = new Scanner(System.in);
		long a = scan.nextLong()-1;
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long x = a - (a / c) - (a / d) + (a / lcm(c, d));
		long y = b - (b / c) - (b / d) + (b / lcm(c, d));

		System.out.println(y-x);

		//12345 7910 
		//
	}

	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);
	}
}