import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		 a -= 1;

		long an = (a - a/c - a/d + (a/(lcm(c, d))));
		long bn = (b - b/c - b/d + (b/(lcm(c, d))));

		System.out.println(bn - an);


	}

	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		 a -= 1;

		long an = (a - a/c - a/d + (a/(lcm(c, d))));
		long bn = (b - b/c - b/d + (b/(lcm(c, d))));

		System.out.println(bn - an);


	}

	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		 a -= 1;

		long an = (a - a/c - a/d + (a/(lcm(c, d))));
		long bn = (b - b/c - b/d + (b/(lcm(c, d))));

		System.out.println(bn - an);


	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		 a -= 1;

		long an = (a - a/c - a/d + (a/(lcm(c, d))));
		long bn = (b - b/c - b/d + (b/(lcm(c, d))));

		System.out.println(bn - an);


	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String str = scan.nextLine(); str scan.nextLine() scan.nextLine scan long a = Long.parseLong(str.split(" ")[0]); a Long.parseLong(str.split(" ")[0]) Long.parseLong Long str.split(" ")[0] str.split(" ") str.split str " " 0 long b = Long.parseLong(str.split(" ")[1]); b Long.parseLong(str.split(" ")[1]) Long.parseLong Long str.split(" ")[1] str.split(" ") str.split str " " 1 long c = Long.parseLong(str.split(" ")[2]); c Long.parseLong(str.split(" ")[2]) Long.parseLong Long str.split(" ")[2] str.split(" ") str.split str " " 2 long d = Long.parseLong(str.split(" ")[3]); d Long.parseLong(str.split(" ")[3]) Long.parseLong Long str.split(" ")[3] str.split(" ") str.split str " " 3 a -= 1 a 1 long an = (a - a/c - a/d + (a/(lcm(c, d)))); an (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 bn = (b - b/c - b/d + (b/(lcm(c, d)))); bn (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(bn - an) System.out.println System.out System System.out bn - an bn an String[] args args static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	} lcm {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	} long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
			a = b;
			b = temp;
		} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
			a = b;
			b = temp;
		} a = b a b b = temp b temp return (long)(c/b); (long)(c/b) c b long a a long b b public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		 a -= 1;

		long an = (a - a/c - a/d + (a/(lcm(c, d))));
		long bn = (b - b/c - b/d + (b/(lcm(c, d))));

		System.out.println(bn - an);


	}

	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}
} public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		 a -= 1;

		long an = (a - a/c - a/d + (a/(lcm(c, d))));
		long bn = (b - b/c - b/d + (b/(lcm(c, d))));

		System.out.println(bn - an);


	}

	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		 a -= 1;

		long an = (a - a/c - a/d + (a/(lcm(c, d))));
		long bn = (b - b/c - b/d + (b/(lcm(c, d))));

		System.out.println(bn - an);


	}

	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}
}
