import java.util.Scanner;

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

		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	}

	public static long euclid(long n, long m) {
		if(m==0) return n;
		return euclid(m, n%m);
	}
} 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() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	}

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

		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	} main {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong() - 1; a sc.nextLong() - 1 sc.nextLong() sc.nextLong sc 1 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 countA = 0; countA 0 long countB = 0; countB 0 long tmp = c * d / euclid(c, d); tmp c * d / euclid(c, d) c * d c d euclid(c, d) euclid c d countA = a - a / c - a / d + a / tmp countA a - a / c - a / d + a / tmp a - a / c - a / d a - a / c - a / d a a / c a c a / d a d a / tmp a tmp countB = b - b / c - b / d + b / tmp countB b - b / c - b / d + b / tmp b - b / c - b / d b - b / c - b / d b b / c b c b / d b d b / tmp b tmp System.out.println(countB - countA) System.out.println System.out System System.out countB - countA countB countA String[] args args public static long euclid(long n, long m) {
		if(m==0) return n;
		return euclid(m, n%m);
	} euclid {
		if(m==0) return n;
		return euclid(m, n%m);
	} if(m==0) return n; m==0 m 0 return n; n return euclid(m, n%m); euclid(m, n%m) euclid m n%m n m long n n long m m public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	}

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

		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	}

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

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

		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	}

	public static long euclid(long n, long m) {
		if(m==0) return n;
		return euclid(m, n%m);
	}
}