import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
} import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
} Main public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	} main {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	} 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 x = B/C-(A-1)/C; x B/C-(A-1)/C B/C B C (A-1)/C (A-1) A 1 C long y = B/D-(A-1)/D; y B/D-(A-1)/D B/D B D (A-1)/D (A-1) A 1 D long z = B/(lcm(C,D))-(A-1)/(lcm(C,D)); z 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 System.out.println(B-A+1-x-y+z) System.out.println System.out System System.out B-A+1-x-y+z B-A+1-x-y B-A+1-x-y B-A+1 B-A B A 1 x y z 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 c/b;
	} lcm {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return 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 c/b; c/b c b long a a long b b public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
} public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
} Main
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
}