import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		long ans = B-A+1;
		long LCM = C*D;
		LCM/=GCD(C,D);
		
		//C
		long lo = A;
		long mod = A%C;
		if (mod!=0) lo+=C-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//D
		lo = A;
		mod = A%D;
		if (mod!=0) lo+=D-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//LCM (Removes counting a valid number twice in range [A,B])
		lo = A;
		mod = A%LCM;
		if (mod!=0) lo+=LCM-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
} import java.io.*; io.* java import java.math.*; math.* java import java.util.*; util.* java public class Main { 
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		long ans = B-A+1;
		long LCM = C*D;
		LCM/=GCD(C,D);
		
		//C
		long lo = A;
		long mod = A%C;
		if (mod!=0) lo+=C-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//D
		lo = A;
		mod = A%D;
		if (mod!=0) lo+=D-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//LCM (Removes counting a valid number twice in range [A,B])
		lo = A;
		mod = A%LCM;
		if (mod!=0) lo+=LCM-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
} Main public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		long ans = B-A+1;
		long LCM = C*D;
		LCM/=GCD(C,D);
		
		//C
		long lo = A;
		long mod = A%C;
		if (mod!=0) lo+=C-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//D
		lo = A;
		mod = A%D;
		if (mod!=0) lo+=D-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//LCM (Removes counting a valid number twice in range [A,B])
		lo = A;
		mod = A%LCM;
		if (mod!=0) lo+=LCM-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		O.pln(ans);
	} main { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		long ans = B-A+1;
		long LCM = C*D;
		LCM/=GCD(C,D);
		
		//C
		long lo = A;
		long mod = A%C;
		if (mod!=0) lo+=C-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//D
		lo = A;
		mod = A%D;
		if (mod!=0) lo+=D-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//LCM (Removes counting a valid number twice in range [A,B])
		lo = A;
		mod = A%LCM;
		if (mod!=0) lo+=LCM-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		O.pln(ans);
	} FastScanner I = new FastScanner(); I new FastScanner() OutPut O = new OutPut(); O new OutPut() long A = I.nextLong(); A I.nextLong() I.nextLong I long B = I.nextLong(); B I.nextLong() I.nextLong I long C = I.nextLong(); C I.nextLong() I.nextLong I long D = I.nextLong(); D I.nextLong() I.nextLong I long ans = B-A+1; ans B-A+1 B-A B A 1 long LCM = C*D; LCM C*D C D LCM/=GCD(C,D) LCM GCD(C,D) GCD C D long lo = A; lo A long mod = A%C; mod A%C A C if (mod!=0) lo+=C-mod; mod!=0 mod 0 lo+=C-mod lo C-mod C mod if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		} lo<=B lo B { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		} long hi = B; hi B hi-=(B%C) hi (B%C) B C long range = hi-lo; range hi-lo hi lo ans-=range/C ans range/C range C ans-- ans lo = A lo A mod = A%D mod A%D A D if (mod!=0) lo+=D-mod; mod!=0 mod 0 lo+=D-mod lo D-mod D mod if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		} lo<=B lo B { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		} long hi = B; hi B hi-=(B%D) hi (B%D) B D long range = hi-lo; range hi-lo hi lo ans-=range/D ans range/D range D ans-- ans lo = A lo A mod = A%LCM mod A%LCM A LCM if (mod!=0) lo+=LCM-mod; mod!=0 mod 0 lo+=LCM-mod lo LCM-mod LCM mod if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		} lo<=B lo B { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		} long hi = B; hi B hi-=(B%LCM) hi (B%LCM) B LCM long range = hi-lo; range hi-lo hi lo ans+=range/LCM ans range/LCM range LCM ans++ ans O.pln(ans) O.pln O ans String[] args args public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;} ceil {long ans = num/den; if (num%den!=0) 
	ans++; return ans;} long ans = num/den; ans num/den num den if (num%den!=0) 
	ans++; num%den!=0 num%den num den 0 ans++ ans return ans; ans long num num long den den public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	} GCD {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	} if (a==0||b==0) return Math.max(a,b); a==0||b==0 a==0 a 0 b==0 b 0 return Math.max(a,b); Math.max(a,b) Math.max Math a b return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b)); GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b)) GCD Math.min(a, b) Math.min Math a b Math.max(a, b)%Math.min(a, b) Math.max(a, b) Math.max Math a b Math.min(a, b) Math.min Math a b long a a long b b public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	} FastExp {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	} long ans=1; ans 1 while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		} exp>0 exp 0 {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		} if (exp%2==1) ans*=base; exp%2==1 exp%2 exp 2 1 ans*=base ans base exp/=2 exp 2 base*=base base base base%=mod base mod ans%=mod ans mod return ans; ans long base base long exp exp long mod mod public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);} ModInv {return FastExp(num,mod-2,mod);} return FastExp(num,mod-2,mod); FastExp(num,mod-2,mod) FastExp num mod-2 mod 2 mod long num num long mod mod static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	} FastScanner BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st=new StringTokenizer(""); st new StringTokenizer("") String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		} next {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		} while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				} !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				} IOException e {
					e.printStackTrace();
				} e.printStackTrace() e.printStackTrace e {
					st=new StringTokenizer(br.readLine());
				} st=new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {return Integer.parseInt(next());} nextInt {return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() {return Long.parseLong(next());} nextLong {return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	} OutPut PrintWriter w = new PrintWriter(System.out); w new PrintWriter(System.out) void pln(int x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w int x x void pln(long x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w long x x void pln(String x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w String x x void pln(char x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w char x x void pln(StringBuilder x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w StringBuilder x x void p(int x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w int x x void p(long x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w long x x void p(String x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w String x x void p(char x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w char x x void p(StringBuilder x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w StringBuilder x x public class Main { 
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		long ans = B-A+1;
		long LCM = C*D;
		LCM/=GCD(C,D);
		
		//C
		long lo = A;
		long mod = A%C;
		if (mod!=0) lo+=C-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//D
		lo = A;
		mod = A%D;
		if (mod!=0) lo+=D-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//LCM (Removes counting a valid number twice in range [A,B])
		lo = A;
		mod = A%LCM;
		if (mod!=0) lo+=LCM-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
} public class Main { 
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		long ans = B-A+1;
		long LCM = C*D;
		LCM/=GCD(C,D);
		
		//C
		long lo = A;
		long mod = A%C;
		if (mod!=0) lo+=C-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//D
		lo = A;
		mod = A%D;
		if (mod!=0) lo+=D-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//LCM (Removes counting a valid number twice in range [A,B])
		lo = A;
		mod = A%LCM;
		if (mod!=0) lo+=LCM-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
} Main
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		long ans = B-A+1;
		long LCM = C*D;
		LCM/=GCD(C,D);
		
		//C
		long lo = A;
		long mod = A%C;
		if (mod!=0) lo+=C-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%C);
			long range = hi-lo;
			ans-=range/C;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//D
		lo = A;
		mod = A%D;
		if (mod!=0) lo+=D-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%D);
			long range = hi-lo;
			ans-=range/D;
			ans--; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		//LCM (Removes counting a valid number twice in range [A,B])
		lo = A;
		mod = A%LCM;
		if (mod!=0) lo+=LCM-mod;
		if (lo<=B) { //If lower bound is within [A,B]
			long hi = B;  //A=5,B=20,C=6 --> hi = 20-20%6 = 18 
			hi-=(B%LCM);
			long range = hi-lo;
			ans+=range/LCM;
			ans++; //If range = [24,24] answer is 1 still (inclusion technique)
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}