import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();

		long v1 = b/c-(a-1)/c;
		long v2 = b/d-(a-1)/d;
		long cd = lcm(c,d);
		long v3 = b/cd-(a-1)/cd;
		System.out.println(b-(a-1)-(v1+v2-v3));
		sc.close();
	}

	public long gcd(long a, long b) {
		if(b==0) return a;
		return gcd(b, a%b);
	}

	public long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();

		long v1 = b/c-(a-1)/c;
		long v2 = b/d-(a-1)/d;
		long cd = lcm(c,d);
		long v3 = b/cd-(a-1)/cd;
		System.out.println(b-(a-1)-(v1+v2-v3));
		sc.close();
	}

	public long gcd(long a, long b) {
		if(b==0) return a;
		return gcd(b, a%b);
	}

	public long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}
} Main public static void main(String[] args) {
		Main main = new Main();
		main.run();
	} main {
		Main main = new Main();
		main.run();
	} Main main = new Main(); main new Main() main.run() main.run main String[] args args public void run() {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();

		long v1 = b/c-(a-1)/c;
		long v2 = b/d-(a-1)/d;
		long cd = lcm(c,d);
		long v3 = b/cd-(a-1)/cd;
		System.out.println(b-(a-1)-(v1+v2-v3));
		sc.close();
	} run {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();

		long v1 = b/c-(a-1)/c;
		long v2 = b/d-(a-1)/d;
		long cd = lcm(c,d);
		long v3 = b/cd-(a-1)/cd;
		System.out.println(b-(a-1)-(v1+v2-v3));
		sc.close();
	} 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 v1 = b/c-(a-1)/c; v1 b/c-(a-1)/c b/c b c (a-1)/c (a-1) a 1 c long v2 = b/d-(a-1)/d; v2 b/d-(a-1)/d b/d b d (a-1)/d (a-1) a 1 d long cd = lcm(c,d); cd lcm(c,d) lcm c d long v3 = b/cd-(a-1)/cd; v3 b/cd-(a-1)/cd b/cd b cd (a-1)/cd (a-1) a 1 cd System.out.println(b-(a-1)-(v1+v2-v3)) System.out.println System.out System System.out b-(a-1)-(v1+v2-v3) b-(a-1)-(v1+v2-v3) b (a-1) a 1 (v1+v2-v3) v1+v2 v1 v2 v3 sc.close() sc.close sc public long gcd(long a, long b) {
		if(b==0) return a;
		return gcd(b, a%b);
	} gcd {
		if(b==0) return a;
		return gcd(b, a%b);
	} if(b==0) return a; 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 public 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) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();

		long v1 = b/c-(a-1)/c;
		long v2 = b/d-(a-1)/d;
		long cd = lcm(c,d);
		long v3 = b/cd-(a-1)/cd;
		System.out.println(b-(a-1)-(v1+v2-v3));
		sc.close();
	}

	public long gcd(long a, long b) {
		if(b==0) return a;
		return gcd(b, a%b);
	}

	public long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}
} public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();

		long v1 = b/c-(a-1)/c;
		long v2 = b/d-(a-1)/d;
		long cd = lcm(c,d);
		long v3 = b/cd-(a-1)/cd;
		System.out.println(b-(a-1)-(v1+v2-v3));
		sc.close();
	}

	public long gcd(long a, long b) {
		if(b==0) return a;
		return gcd(b, a%b);
	}

	public long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();

		long v1 = b/c-(a-1)/c;
		long v2 = b/d-(a-1)/d;
		long cd = lcm(c,d);
		long v3 = b/cd-(a-1)/cd;
		System.out.println(b-(a-1)-(v1+v2-v3));
		sc.close();
	}

	public long gcd(long a, long b) {
		if(b==0) return a;
		return gcd(b, a%b);
	}

	public long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}
}
