import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long range=b-a+1, min=lcm(c,d);
		long c_div=b/c-(a-1)/c, d_div=b/d-(a-1)/d, common_div=b/min-(a-1)/min;
		System.out.println(range-(c_div+d_div-common_div));
	}

	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(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long range=b-a+1, min=lcm(c,d);
		long c_div=b/c-(a-1)/c, d_div=b/d-(a-1)/d, common_div=b/min-(a-1)/min;
		System.out.println(range-(c_div+d_div-common_div));
	}

	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(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long range=b-a+1, min=lcm(c,d);
		long c_div=b/c-(a-1)/c, d_div=b/d-(a-1)/d, common_div=b/min-(a-1)/min;
		System.out.println(range-(c_div+d_div-common_div));
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long range=b-a+1, min=lcm(c,d);
		long c_div=b/c-(a-1)/c, d_div=b/d-(a-1)/d, common_div=b/min-(a-1)/min;
		System.out.println(range-(c_div+d_div-common_div));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong() a sc.nextLong() sc.nextLong sc b=sc.nextLong() b sc.nextLong() sc.nextLong sc c=sc.nextLong() c sc.nextLong() sc.nextLong sc d=sc.nextLong(); d sc.nextLong() sc.nextLong sc long range=b-a+1 range b-a+1 b-a b a 1 min=lcm(c,d); min lcm(c,d) lcm c d long c_div=b/c-(a-1)/c c_div b/c-(a-1)/c b/c b c (a-1)/c (a-1) a 1 c d_div=b/d-(a-1)/d d_div b/d-(a-1)/d b/d b d (a-1)/d (a-1) a 1 d common_div=b/min-(a-1)/min; common_div b/min-(a-1)/min b/min b min (a-1)/min (a-1) a 1 min System.out.println(range-(c_div+d_div-common_div)) System.out.println System.out System System.out range-(c_div+d_div-common_div) range (c_div+d_div-common_div) c_div+d_div c_div d_div common_div 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(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long range=b-a+1, min=lcm(c,d);
		long c_div=b/c-(a-1)/c, d_div=b/d-(a-1)/d, common_div=b/min-(a-1)/min;
		System.out.println(range-(c_div+d_div-common_div));
	}

	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(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long range=b-a+1, min=lcm(c,d);
		long c_div=b/c-(a-1)/c, d_div=b/d-(a-1)/d, common_div=b/min-(a-1)/min;
		System.out.println(range-(c_div+d_div-common_div));
	}

	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(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long range=b-a+1, min=lcm(c,d);
		long c_div=b/c-(a-1)/c, d_div=b/d-(a-1)/d, common_div=b/min-(a-1)/min;
		System.out.println(range-(c_div+d_div-common_div));
	}

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