import java.util.Scanner;

	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();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    }
		
		static long calc(long i,long j) {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		}
		
		static long lcm (long a, long b) {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(c/b);
		}
				
	} import java.util.Scanner; Scanner 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();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    }
		
		static long calc(long i,long j) {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		}
		
		static long lcm (long a, long b) {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(c/b);
		}
				
	} 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();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    } main {

			Scanner sc = new Scanner(System.in);
			
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    } 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 ret = 0; ret 0 long stc = a/c; stc a/c a c long enc = b/c; enc b/c b c long std = a/d; std a/d a d long end = b/d; end b/d b d System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1))) System.out.println System.out System System.out (b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)) (b-a+1) b-a b a 1 ((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)) (b/c-calc(a,c)+1)+(b/d-calc(a,d)+1) (b/c-calc(a,c)+1) b/c-calc(a,c) b/c b c calc(a,c) calc a c 1 (b/d-calc(a,d)+1) b/d-calc(a,d) b/d b d calc(a,d) calc a d 1 (b/(lcm(c,d))-calc(a,lcm(c,d))+1) b/(lcm(c,d))-calc(a,lcm(c,d)) b/(lcm(c,d)) b (lcm(c,d)) lcm c d calc(a,lcm(c,d)) calc a lcm(c,d) lcm c d 1 String[] args args static long calc(long i,long j) {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		} calc {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		} if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			} i%j==0 i%j i j 0 {
				return i/j;
			} return i/j; i/j i j {
				return i/j+1;
			} return i/j+1; i/j+1 i/j i j 1 long i i long j j static long lcm (long a, long b) {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(c/b);
		} lcm {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(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 (long)(c/b); (long)(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();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    }
		
		static long calc(long i,long j) {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		}
		
		static long lcm (long a, long b) {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(c/b);
		}
				
	} 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();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    }
		
		static long calc(long i,long j) {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		}
		
		static long lcm (long a, long b) {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(c/b);
		}
				
	} Main
import java.util.Scanner;

	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();
			long ret = 0;
			
			long stc = a/c;
			long enc = b/c;
			long std = a/d;
			long end = b/d;
			

			
			System.out.println((b-a+1)-((b/c-calc(a,c)+1)+(b/d-calc(a,d)+1)-(b/(lcm(c,d))-calc(a,lcm(c,d))+1)));
			
	    }
		
		static long calc(long i,long j) {
			if(i%j==0) {
				return i/j;
			}else {
				return i/j+1;
			}
		}
		
		static long lcm (long a, long b) {
			long temp;
			long c = a;
			c *= b;
			while((temp = a%b)!=0) {
				a = b;
				b = temp;
			}
			return (long)(c/b);
		}
				
	}
