import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong()-1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long l = lcm(c,d);

		long countA = a - (a/c + a/d - a/l);
		long countB = b - (b/c + b/d - b/l);
		
		long ans = countB - countA;
		System.out.println(ans);
		
		
		sc.close();
	}
	
	public static long lcm(long a, long b)  {
		long c = a * b;
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		
		return c/b;
	}
	
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong()-1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long l = lcm(c,d);

		long countA = a - (a/c + a/d - a/l);
		long countB = b - (b/c + b/d - b/l);
		
		long ans = countB - countA;
		System.out.println(ans);
		
		
		sc.close();
	}
	
	public static long lcm(long a, long b)  {
		long c = a * b;
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		
		return c/b;
	}
	
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong()-1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long l = lcm(c,d);

		long countA = a - (a/c + a/d - a/l);
		long countB = b - (b/c + b/d - b/l);
		
		long ans = countB - countA;
		System.out.println(ans);
		
		
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong()-1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long l = lcm(c,d);

		long countA = a - (a/c + a/d - a/l);
		long countB = b - (b/c + b/d - b/l);
		
		long ans = countB - countA;
		System.out.println(ans);
		
		
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong()-1; a sc.nextLong()-1 sc.nextLong() sc.nextLong sc 1 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 l = lcm(c,d); l lcm(c,d) lcm c d long countA = a - (a/c + a/d - a/l); countA a - (a/c + a/d - a/l) a (a/c + a/d - a/l) a/c + a/d a/c a c a/d a d a/l a l long countB = b - (b/c + b/d - b/l); countB b - (b/c + b/d - b/l) b (b/c + b/d - b/l) b/c + b/d b/c b c b/d b d b/l b l long ans = countB - countA; ans countB - countA countB countA System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public static long lcm(long a, long b)  {
		long c = a * b;
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		
		return c/b;
	} lcm {
		long c = a * b;
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		
		return c/b;
	} long c = a * b; c a * b a b long temp; temp 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) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong()-1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long l = lcm(c,d);

		long countA = a - (a/c + a/d - a/l);
		long countB = b - (b/c + b/d - b/l);
		
		long ans = countB - countA;
		System.out.println(ans);
		
		
		sc.close();
	}
	
	public static long lcm(long a, long b)  {
		long c = a * b;
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		
		return c/b;
	}
	
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong()-1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long l = lcm(c,d);

		long countA = a - (a/c + a/d - a/l);
		long countB = b - (b/c + b/d - b/l);
		
		long ans = countB - countA;
		System.out.println(ans);
		
		
		sc.close();
	}
	
	public static long lcm(long a, long b)  {
		long c = a * b;
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		
		return c/b;
	}
	
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong()-1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long l = lcm(c,d);

		long countA = a - (a/c + a/d - a/l);
		long countB = b - (b/c + b/d - b/l);
		
		long ans = countB - countA;
		System.out.println(ans);
		
		
		sc.close();
	}
	
	public static long lcm(long a, long b)  {
		long c = a * b;
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		
		return c/b;
	}
	
}
