import java.util.*;

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

public 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();
		
		System.out.println(count(B, C, D) - count(A-1, C, D));
		sc.close();
	}
	
	static long gcd(long a, long b) {
		return a==0 ? b : gcd(b%a, a);
	}
	
	static long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}
	
	static long count(long x, long c, long d) {
		return x - x/c - x/d + x/lcm(c,d);
	}
}