import java.util.Scanner;
public class Main {
	static long gcd(long a,long b) {
		long temp = 0;
		while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		}
		return b;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long p = c > d ? gcd(c,d):gcd(d,c);
		long k = (long)c*d/p;
		
		long ansb = b -(b/c + b/d - b/k);
		long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k);
		System.out.println(ansb -ansa);

	}

} import java.util.Scanner; Scanner java.util public class Main {
	static long gcd(long a,long b) {
		long temp = 0;
		while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		}
		return b;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long p = c > d ? gcd(c,d):gcd(d,c);
		long k = (long)c*d/p;
		
		long ansb = b -(b/c + b/d - b/k);
		long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k);
		System.out.println(ansb -ansa);

	}

} Main static long gcd(long a,long b) {
		long temp = 0;
		while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		}
		return b;
	} gcd {
		long temp = 0;
		while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		}
		return b;
	} long temp = 0; temp 0 while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		} a % b != 0 a % b a b 0 {
			temp = a;
			a = b;
			b = temp % b;
		} temp = a temp a a = b a b b = temp % b b temp % b temp b return b; b long a a long b b public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long p = c > d ? gcd(c,d):gcd(d,c);
		long k = (long)c*d/p;
		
		long ansb = b -(b/c + b/d - b/k);
		long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k);
		System.out.println(ansb -ansa);

	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long p = c > d ? gcd(c,d):gcd(d,c);
		long k = (long)c*d/p;
		
		long ansb = b -(b/c + b/d - b/k);
		long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k);
		System.out.println(ansb -ansa);

	} 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 int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc long p = c > d ? gcd(c,d):gcd(d,c); p c > d ? gcd(c,d):gcd(d,c) c > d c d gcd(c,d) gcd c d gcd(d,c) gcd d c long k = (long)c*d/p; k (long)c*d/p (long)c*d (long)c d p long ansb = b -(b/c + b/d - b/k); ansb b -(b/c + b/d - b/k) b (b/c + b/d - b/k) b/c + b/d b/c b c b/d b d b/k b k long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k); ansa (a -1) -((a-1)/c+(a-1)/d-(a-1)/k) (a -1) a 1 ((a-1)/c+(a-1)/d-(a-1)/k) (a-1)/c+(a-1)/d (a-1)/c (a-1) a 1 c (a-1)/d (a-1) a 1 d (a-1)/k (a-1) a 1 k System.out.println(ansb -ansa) System.out.println System.out System System.out ansb -ansa ansb ansa String[] args args public class Main {
	static long gcd(long a,long b) {
		long temp = 0;
		while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		}
		return b;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long p = c > d ? gcd(c,d):gcd(d,c);
		long k = (long)c*d/p;
		
		long ansb = b -(b/c + b/d - b/k);
		long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k);
		System.out.println(ansb -ansa);

	}

} public class Main {
	static long gcd(long a,long b) {
		long temp = 0;
		while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		}
		return b;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long p = c > d ? gcd(c,d):gcd(d,c);
		long k = (long)c*d/p;
		
		long ansb = b -(b/c + b/d - b/k);
		long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k);
		System.out.println(ansb -ansa);

	}

} Main
import java.util.Scanner;
public class Main {
	static long gcd(long a,long b) {
		long temp = 0;
		while(a % b != 0) {
			temp = a;
			a = b;
			b = temp % b;
		}
		return b;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long p = c > d ? gcd(c,d):gcd(d,c);
		long k = (long)c*d/p;
		
		long ansb = b -(b/c + b/d - b/k);
		long ansa = (a -1) -((a-1)/c+(a-1)/d-(a-1)/k);
		System.out.println(ansb -ansa);

	}

}
