import java.util.Scanner;

public class Main {

	// c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	}

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

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	}
}
 import java.util.Scanner; Scanner java.util public class Main {

	// c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	}

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

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	}
} Main // c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	} eukleides {
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	} if(d % c == 0){
			return c;
		} d % c == 0 d % c d c 0 {
			return c;
		} return c; c long mod = d % c; mod d % c d c return eukleides(mod, c); eukleides(mod, c) eukleides mod c long c c long d d public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

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

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a = scan.nextLong(); a scan.nextLong() scan.nextLong scan long b = scan.nextLong(); b scan.nextLong() scan.nextLong scan long c = scan.nextInt(); c scan.nextInt() scan.nextInt scan long d = scan.nextInt(); d scan.nextInt() scan.nextInt scan if(c > d){
			long temp = c;
			c = d;
			d = temp;
		} c > d c d {
			long temp = c;
			c = d;
			d = temp;
		} long temp = c; temp c c = d c d d = temp d temp long gcd = eukleides(c, d); gcd eukleides(c, d) eukleides c d long lcm = (c * d) / gcd; lcm (c * d) / gcd (c * d) c d gcd long answer = b - b / c - b / d + b / lcm; answer b - b / c - b / d + b / lcm b - b / c - b / d b - b / c - b / d b b / c b c b / d b d b / lcm b lcm answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm answer a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm a - 1 - (a - 1) / c - (a - 1) / d (a - 1) / c a - 1 - (a - 1) / c - (a - 1) / d a 1 (a - 1) / c (a - 1) a 1 c (a - 1) / d (a - 1) a 1 d (a - 1) / lcm (a - 1) a 1 lcm System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	// c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	}

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

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	}
} public class Main {

	// c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	}

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

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	}
} Main
import java.util.Scanner;

public class Main {

	// c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	}

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

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	}
}

