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 multCD = lcm(C, D);

		long CRem = B / C - (A - 1) / C;
		long DRem = B / D - (A - 1) / D;
		long multCDRem = B / multCD - (A - 1) / multCD;

		System.out.println(B - A + 1 - (CRem + DRem - multCDRem));
	}

	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) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long multCD = lcm(C, D);

		long CRem = B / C - (A - 1) / C;
		long DRem = B / D - (A - 1) / D;
		long multCDRem = B / multCD - (A - 1) / multCD;

		System.out.println(B - A + 1 - (CRem + DRem - multCDRem));
	}

	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) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long multCD = lcm(C, D);

		long CRem = B / C - (A - 1) / C;
		long DRem = B / D - (A - 1) / D;
		long multCDRem = B / multCD - (A - 1) / multCD;

		System.out.println(B - A + 1 - (CRem + DRem - multCDRem));
	} main {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long multCD = lcm(C, D);

		long CRem = B / C - (A - 1) / C;
		long DRem = B / D - (A - 1) / D;
		long multCDRem = B / multCD - (A - 1) / multCD;

		System.out.println(B - A + 1 - (CRem + DRem - multCDRem));
	} 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 multCD = lcm(C, D); multCD lcm(C, D) lcm C D long CRem = B / C - (A - 1) / C; CRem B / C - (A - 1) / C B / C B C (A - 1) / C (A - 1) A 1 C long DRem = B / D - (A - 1) / D; DRem B / D - (A - 1) / D B / D B D (A - 1) / D (A - 1) A 1 D long multCDRem = B / multCD - (A - 1) / multCD; multCDRem B / multCD - (A - 1) / multCD B / multCD B multCD (A - 1) / multCD (A - 1) A 1 multCD System.out.println(B - A + 1 - (CRem + DRem - multCDRem)) System.out.println System.out System System.out B - A + 1 - (CRem + DRem - multCDRem) B - A + 1 B - A B A 1 (CRem + DRem - multCDRem) CRem + DRem CRem DRem multCDRem 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) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long multCD = lcm(C, D);

		long CRem = B / C - (A - 1) / C;
		long DRem = B / D - (A - 1) / D;
		long multCDRem = B / multCD - (A - 1) / multCD;

		System.out.println(B - A + 1 - (CRem + DRem - multCDRem));
	}

	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) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long multCD = lcm(C, D);

		long CRem = B / C - (A - 1) / C;
		long DRem = B / D - (A - 1) / D;
		long multCDRem = B / multCD - (A - 1) / multCD;

		System.out.println(B - A + 1 - (CRem + DRem - multCDRem));
	}

	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) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long multCD = lcm(C, D);

		long CRem = B / C - (A - 1) / C;
		long DRem = B / D - (A - 1) / D;
		long multCDRem = B / multCD - (A - 1) / multCD;

		System.out.println(B - A + 1 - (CRem + DRem - multCDRem));
	}

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