import java.util.*;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	long a = sc.nextLong();
      	long b = sc.nextLong();
      	long c = sc.nextLong();
      	long d = sc.nextLong();
      	sc.close();
      
		long min = count(a - 1, c, d);
		long max = count(b, c, d);
      	System.out.println(max - min);
    }
  
  	public static long count(long x, long c, long d) {
    	return (x - ((x / c) + (x / d) - (x / (lcm(c, d)))));
    }
  
  	public static long lcm(long a, long b) {
    	long g = gcd(a, b);
      	return (a * b) / g;
    }
  
  	public static long gcd(long a, long b) {
    	if (a > b) {
			long tmp = a;
          	a = b;
          	b = tmp;
        }
      	if (a == 0) return b;
      	return gcd(b % a, a);
    }
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	long a = sc.nextLong();
      	long b = sc.nextLong();
      	long c = sc.nextLong();
      	long d = sc.nextLong();
      	sc.close();
      
		long min = count(a - 1, c, d);
		long max = count(b, c, d);
      	System.out.println(max - min);
    }
  
  	public static long count(long x, long c, long d) {
    	return (x - ((x / c) + (x / d) - (x / (lcm(c, d)))));
    }
  
  	public static long lcm(long a, long b) {
    	long g = gcd(a, b);
      	return (a * b) / g;
    }
  
  	public static long gcd(long a, long b) {
    	if (a > b) {
			long tmp = a;
          	a = b;
          	b = tmp;
        }
      	if (a == 0) return b;
      	return gcd(b % a, a);
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	long a = sc.nextLong();
      	long b = sc.nextLong();
      	long c = sc.nextLong();
      	long d = sc.nextLong();
      	sc.close();
      
		long min = count(a - 1, c, d);
		long max = count(b, c, d);
      	System.out.println(max - min);
    } main {
    	Scanner sc = new Scanner(System.in);
      	long a = sc.nextLong();
      	long b = sc.nextLong();
      	long c = sc.nextLong();
      	long d = sc.nextLong();
      	sc.close();
      
		long min = count(a - 1, c, d);
		long max = count(b, c, d);
      	System.out.println(max - min);
    } 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 sc.close() sc.close sc long min = count(a - 1, c, d); min count(a - 1, c, d) count a - 1 a 1 c d long max = count(b, c, d); max count(b, c, d) count b c d System.out.println(max - min) System.out.println System.out System System.out max - min max min String[] args args public static long count(long x, long c, long d) {
    	return (x - ((x / c) + (x / d) - (x / (lcm(c, d)))));
    } count {
    	return (x - ((x / c) + (x / d) - (x / (lcm(c, d)))));
    } return (x - ((x / c) + (x / d) - (x / (lcm(c, d))))); (x - ((x / c) + (x / d) - (x / (lcm(c, d))))) x ((x / c) + (x / d) - (x / (lcm(c, d)))) (x / c) + (x / d) (x / c) x c (x / d) x d (x / (lcm(c, d))) x (lcm(c, d)) lcm c d long x x long c c long d d public static long lcm(long a, long b) {
    	long g = gcd(a, b);
      	return (a * b) / g;
    } lcm {
    	long g = gcd(a, b);
      	return (a * b) / g;
    } long g = gcd(a, b); g gcd(a, b) gcd a b return (a * b) / g; (a * b) / g (a * b) a b g long a a long b b public static long gcd(long a, long b) {
    	if (a > b) {
			long tmp = a;
          	a = b;
          	b = tmp;
        }
      	if (a == 0) return b;
      	return gcd(b % a, a);
    } gcd {
    	if (a > b) {
			long tmp = a;
          	a = b;
          	b = tmp;
        }
      	if (a == 0) return b;
      	return gcd(b % a, a);
    } if (a > b) {
			long tmp = a;
          	a = b;
          	b = tmp;
        } a > b a b {
			long tmp = a;
          	a = b;
          	b = tmp;
        } long tmp = a; tmp a a = b a b b = tmp b tmp if (a == 0) return b; a == 0 a 0 return b; b return gcd(b % a, a); gcd(b % a, a) gcd b % a b a a long a a long b b
import java.util.*;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	long a = sc.nextLong();
      	long b = sc.nextLong();
      	long c = sc.nextLong();
      	long d = sc.nextLong();
      	sc.close();
      
		long min = count(a - 1, c, d);
		long max = count(b, c, d);
      	System.out.println(max - min);
    }
  
  	public static long count(long x, long c, long d) {
    	return (x - ((x / c) + (x / d) - (x / (lcm(c, d)))));
    }
  
  	public static long lcm(long a, long b) {
    	long g = gcd(a, b);
      	return (a * b) / g;
    }
  
  	public static long gcd(long a, long b) {
    	if (a > b) {
			long tmp = a;
          	a = b;
          	b = tmp;
        }
      	if (a == 0) return b;
      	return gcd(b % a, a);
    }
}