import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

}
class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {
		 long A = sc.nextLong();
		 long B = sc.nextLong();
		 long C = sc.nextLong();
		 long D = sc.nextLong();

		 long last_d=0;
		 long last_cd=0;
		 long last_c,first_c,first_d,first_cd;

		 long gcd=getGCD(C,D);
		 long lcm=getLCM(C,D,gcd);
		 if(B%C==0) {
			 last_c=B/C;
		 }else {
			 last_c=B/C;
		 }
		 if(A%C==0) {
			 first_c=A/C;
		 }else {
			 first_c=A/C+1;
		 }

		 if(B%D==0) {
			 last_d=B/D;
		 }else {
			 last_d=B/D;
		 }
		 if(A%D==0) {
			 first_d=A/D;
		 }else {
			 first_d=A/D+1;
		 }

		 if(B%lcm==0) {
			 last_cd=B/lcm;
		 }else {
			 last_cd=B/lcm;
		 }
		 if(A%lcm==0) {
			 first_cd=A/lcm;
		 }else {
			 first_cd=A/lcm+1;
		 }



		 long c=last_c-first_c+1;
		 long d=last_d-first_d+1;
		 long cd=last_cd-first_cd+1;
		 long res=c+d-cd;


	//	 System.out.println(last_d);


		 System.out.println(B-A+1-res);
	}
	 private static long getGCD(long a,long b) {

		 if(b==0) return a;
			 return getGCD(b,a%b);
	 }
	 private static long getLCM(long a,long b,long gcd) {

		 return a*b/gcd;

		 }
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	} Solve s= new Solve(); s new Solve() s.solve() s.solve s String[] args args class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {
		 long A = sc.nextLong();
		 long B = sc.nextLong();
		 long C = sc.nextLong();
		 long D = sc.nextLong();

		 long last_d=0;
		 long last_cd=0;
		 long last_c,first_c,first_d,first_cd;

		 long gcd=getGCD(C,D);
		 long lcm=getLCM(C,D,gcd);
		 if(B%C==0) {
			 last_c=B/C;
		 }else {
			 last_c=B/C;
		 }
		 if(A%C==0) {
			 first_c=A/C;
		 }else {
			 first_c=A/C+1;
		 }

		 if(B%D==0) {
			 last_d=B/D;
		 }else {
			 last_d=B/D;
		 }
		 if(A%D==0) {
			 first_d=A/D;
		 }else {
			 first_d=A/D+1;
		 }

		 if(B%lcm==0) {
			 last_cd=B/lcm;
		 }else {
			 last_cd=B/lcm;
		 }
		 if(A%lcm==0) {
			 first_cd=A/lcm;
		 }else {
			 first_cd=A/lcm+1;
		 }



		 long c=last_c-first_c+1;
		 long d=last_d-first_d+1;
		 long cd=last_cd-first_cd+1;
		 long res=c+d-cd;


	//	 System.out.println(last_d);


		 System.out.println(B-A+1-res);
	}
	 private static long getGCD(long a,long b) {

		 if(b==0) return a;
			 return getGCD(b,a%b);
	 }
	 private static long getLCM(long a,long b,long gcd) {

		 return a*b/gcd;

		 }
} Solve Scanner sc = new Scanner(System.in) ; sc new Scanner(System.in) void solve() {
		 long A = sc.nextLong();
		 long B = sc.nextLong();
		 long C = sc.nextLong();
		 long D = sc.nextLong();

		 long last_d=0;
		 long last_cd=0;
		 long last_c,first_c,first_d,first_cd;

		 long gcd=getGCD(C,D);
		 long lcm=getLCM(C,D,gcd);
		 if(B%C==0) {
			 last_c=B/C;
		 }else {
			 last_c=B/C;
		 }
		 if(A%C==0) {
			 first_c=A/C;
		 }else {
			 first_c=A/C+1;
		 }

		 if(B%D==0) {
			 last_d=B/D;
		 }else {
			 last_d=B/D;
		 }
		 if(A%D==0) {
			 first_d=A/D;
		 }else {
			 first_d=A/D+1;
		 }

		 if(B%lcm==0) {
			 last_cd=B/lcm;
		 }else {
			 last_cd=B/lcm;
		 }
		 if(A%lcm==0) {
			 first_cd=A/lcm;
		 }else {
			 first_cd=A/lcm+1;
		 }



		 long c=last_c-first_c+1;
		 long d=last_d-first_d+1;
		 long cd=last_cd-first_cd+1;
		 long res=c+d-cd;


	//	 System.out.println(last_d);


		 System.out.println(B-A+1-res);
	} solve {
		 long A = sc.nextLong();
		 long B = sc.nextLong();
		 long C = sc.nextLong();
		 long D = sc.nextLong();

		 long last_d=0;
		 long last_cd=0;
		 long last_c,first_c,first_d,first_cd;

		 long gcd=getGCD(C,D);
		 long lcm=getLCM(C,D,gcd);
		 if(B%C==0) {
			 last_c=B/C;
		 }else {
			 last_c=B/C;
		 }
		 if(A%C==0) {
			 first_c=A/C;
		 }else {
			 first_c=A/C+1;
		 }

		 if(B%D==0) {
			 last_d=B/D;
		 }else {
			 last_d=B/D;
		 }
		 if(A%D==0) {
			 first_d=A/D;
		 }else {
			 first_d=A/D+1;
		 }

		 if(B%lcm==0) {
			 last_cd=B/lcm;
		 }else {
			 last_cd=B/lcm;
		 }
		 if(A%lcm==0) {
			 first_cd=A/lcm;
		 }else {
			 first_cd=A/lcm+1;
		 }



		 long c=last_c-first_c+1;
		 long d=last_d-first_d+1;
		 long cd=last_cd-first_cd+1;
		 long res=c+d-cd;


	//	 System.out.println(last_d);


		 System.out.println(B-A+1-res);
	} 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 last_d=0; last_d 0 long last_cd=0; last_cd 0 long last_c last_c first_c first_c first_d first_d first_cd; first_cd long gcd=getGCD(C,D); gcd getGCD(C,D) getGCD C D long lcm=getLCM(C,D,gcd); lcm getLCM(C,D,gcd) getLCM C D gcd if(B%C==0) {
			 last_c=B/C;
		 }else {
			 last_c=B/C;
		 } B%C==0 B%C B C 0 {
			 last_c=B/C;
		 } last_c=B/C last_c B/C B C {
			 last_c=B/C;
		 } last_c=B/C last_c B/C B C if(A%C==0) {
			 first_c=A/C;
		 }else {
			 first_c=A/C+1;
		 } A%C==0 A%C A C 0 {
			 first_c=A/C;
		 } first_c=A/C first_c A/C A C {
			 first_c=A/C+1;
		 } first_c=A/C+1 first_c A/C+1 A/C A C 1 if(B%D==0) {
			 last_d=B/D;
		 }else {
			 last_d=B/D;
		 } B%D==0 B%D B D 0 {
			 last_d=B/D;
		 } last_d=B/D last_d B/D B D {
			 last_d=B/D;
		 } last_d=B/D last_d B/D B D if(A%D==0) {
			 first_d=A/D;
		 }else {
			 first_d=A/D+1;
		 } A%D==0 A%D A D 0 {
			 first_d=A/D;
		 } first_d=A/D first_d A/D A D {
			 first_d=A/D+1;
		 } first_d=A/D+1 first_d A/D+1 A/D A D 1 if(B%lcm==0) {
			 last_cd=B/lcm;
		 }else {
			 last_cd=B/lcm;
		 } B%lcm==0 B%lcm B lcm 0 {
			 last_cd=B/lcm;
		 } last_cd=B/lcm last_cd B/lcm B lcm {
			 last_cd=B/lcm;
		 } last_cd=B/lcm last_cd B/lcm B lcm if(A%lcm==0) {
			 first_cd=A/lcm;
		 }else {
			 first_cd=A/lcm+1;
		 } A%lcm==0 A%lcm A lcm 0 {
			 first_cd=A/lcm;
		 } first_cd=A/lcm first_cd A/lcm A lcm {
			 first_cd=A/lcm+1;
		 } first_cd=A/lcm+1 first_cd A/lcm+1 A/lcm A lcm 1 long c=last_c-first_c+1; c last_c-first_c+1 last_c-first_c last_c first_c 1 long d=last_d-first_d+1; d last_d-first_d+1 last_d-first_d last_d first_d 1 long cd=last_cd-first_cd+1; cd last_cd-first_cd+1 last_cd-first_cd last_cd first_cd 1 long res=c+d-cd; res c+d-cd c+d c d cd System.out.println(B-A+1-res) System.out.println System.out System System.out B-A+1-res B-A+1 B-A B A 1 res private static long getGCD(long a,long b) {

		 if(b==0) return a;
			 return getGCD(b,a%b);
	 } getGCD {

		 if(b==0) return a;
			 return getGCD(b,a%b);
	 } if(b==0) return a; b==0 b 0 return a; a return getGCD(b,a%b); getGCD(b,a%b) getGCD b a%b a b long a a long b b private static long getLCM(long a,long b,long gcd) {

		 return a*b/gcd;

		 } getLCM {

		 return a*b/gcd;

		 } return a*b/gcd; a*b/gcd a*b a b gcd long a a long b b long gcd gcd public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

}
class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {
		 long A = sc.nextLong();
		 long B = sc.nextLong();
		 long C = sc.nextLong();
		 long D = sc.nextLong();

		 long last_d=0;
		 long last_cd=0;
		 long last_c,first_c,first_d,first_cd;

		 long gcd=getGCD(C,D);
		 long lcm=getLCM(C,D,gcd);
		 if(B%C==0) {
			 last_c=B/C;
		 }else {
			 last_c=B/C;
		 }
		 if(A%C==0) {
			 first_c=A/C;
		 }else {
			 first_c=A/C+1;
		 }

		 if(B%D==0) {
			 last_d=B/D;
		 }else {
			 last_d=B/D;
		 }
		 if(A%D==0) {
			 first_d=A/D;
		 }else {
			 first_d=A/D+1;
		 }

		 if(B%lcm==0) {
			 last_cd=B/lcm;
		 }else {
			 last_cd=B/lcm;
		 }
		 if(A%lcm==0) {
			 first_cd=A/lcm;
		 }else {
			 first_cd=A/lcm+1;
		 }



		 long c=last_c-first_c+1;
		 long d=last_d-first_d+1;
		 long cd=last_cd-first_cd+1;
		 long res=c+d-cd;


	//	 System.out.println(last_d);


		 System.out.println(B-A+1-res);
	}
	 private static long getGCD(long a,long b) {

		 if(b==0) return a;
			 return getGCD(b,a%b);
	 }
	 private static long getLCM(long a,long b,long gcd) {

		 return a*b/gcd;

		 }
}