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 cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	}

	//整数a,bの最大公約数
	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	}

	//整数a,bの最小公倍数
	public static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}
} 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 cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	}

	//整数a,bの最大公約数
	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	}

	//整数a,bの最小公倍数
	public static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}
} 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 cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	} main {

		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	} 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 cnum = (B/C) - ((A-1)/C); cnum (B/C) - ((A-1)/C) (B/C) B C ((A-1)/C) (A-1) A 1 C long dnum = (B/D) - ((A-1)/D); dnum (B/D) - ((A-1)/D) (B/D) B D ((A-1)/D) (A-1) A 1 D long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D)); cdnum (B/lcm(C,D)) - ((A-1)/lcm(C,D)) (B/lcm(C,D)) B lcm(C,D) lcm C D ((A-1)/lcm(C,D)) (A-1) A 1 lcm(C,D) lcm C D long ans = (B-A+1) - (cnum + dnum - cdnum); ans (B-A+1) - (cnum + dnum - cdnum) (B-A+1) B-A B A 1 (cnum + dnum - cdnum) cnum + dnum cnum dnum cdnum System.out.println(ans) System.out.println System.out System System.out ans String args[] args //整数a,bの最大公約数
	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	} gcd {
		if(b == 0) return a;
		else return gcd(b,a%b);
	} if(b == 0) return a;
		else return gcd(b,a%b); b == 0 b 0 return a; a return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b //整数a,bの最小公倍数
	public static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	} lcm {
		return a*b/gcd(a,b);
	} return a*b/gcd(a,b); a*b/gcd(a,b) a*b a b gcd(a,b) gcd a b long a a long b b 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 cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	}

	//整数a,bの最大公約数
	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	}

	//整数a,bの最小公倍数
	public static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}
} 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 cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	}

	//整数a,bの最大公約数
	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	}

	//整数a,bの最小公倍数
	public static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}
} 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 cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	}

	//整数a,bの最大公約数
	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	}

	//整数a,bの最小公倍数
	public static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}
}
