import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static char[][] map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();

		long key = lcm(C, D);
//		System.out.println(key);
		long ans = 0;
		
		ans += (B/C - A/C) + (B/D - A/D) - (B/key - A/key);
//		System.out.println((B/C - A/C)+1);
//
//		System.out.println((B/D - A/D) + 1);
//		System.out.println((B/key - A/key)+1);


		if(A%C == 0){
			ans++;
		}
		if(A%D == 0){
			ans++;
		}
		if(A%key == 0){
			ans--;
		}
		System.out.println(B-A+1-ans);
		
		

	}

	static int rsearch(int y,int x){

		int count = 0;
		while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		}
		return count;	

	}

	static int csearch(int y,int x){

		int count = 0;
		while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		}
		return count;	
	}


	static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){

		//		System.out.println("bit " + bit);

		for(int i = 0;i < m;i++){

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		}


		return true;

	}

	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}

 import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Main{


	static char[][] map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();

		long key = lcm(C, D);
//		System.out.println(key);
		long ans = 0;
		
		ans += (B/C - A/C) + (B/D - A/D) - (B/key - A/key);
//		System.out.println((B/C - A/C)+1);
//
//		System.out.println((B/D - A/D) + 1);
//		System.out.println((B/key - A/key)+1);


		if(A%C == 0){
			ans++;
		}
		if(A%D == 0){
			ans++;
		}
		if(A%key == 0){
			ans--;
		}
		System.out.println(B-A+1-ans);
		
		

	}

	static int rsearch(int y,int x){

		int count = 0;
		while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		}
		return count;	

	}

	static int csearch(int y,int x){

		int count = 0;
		while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		}
		return count;	
	}


	static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){

		//		System.out.println("bit " + bit);

		for(int i = 0;i < m;i++){

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		}


		return true;

	}

	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




} Main static char[][] map; map public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();

		long key = lcm(C, D);
//		System.out.println(key);
		long ans = 0;
		
		ans += (B/C - A/C) + (B/D - A/D) - (B/key - A/key);
//		System.out.println((B/C - A/C)+1);
//
//		System.out.println((B/D - A/D) + 1);
//		System.out.println((B/key - A/key)+1);


		if(A%C == 0){
			ans++;
		}
		if(A%D == 0){
			ans++;
		}
		if(A%key == 0){
			ans--;
		}
		System.out.println(B-A+1-ans);
		
		

	} main {
		Scanner sc = new Scanner(System.in);			//文字の入力



		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();

		long key = lcm(C, D);
//		System.out.println(key);
		long ans = 0;
		
		ans += (B/C - A/C) + (B/D - A/D) - (B/key - A/key);
//		System.out.println((B/C - A/C)+1);
//
//		System.out.println((B/D - A/D) + 1);
//		System.out.println((B/key - A/key)+1);


		if(A%C == 0){
			ans++;
		}
		if(A%D == 0){
			ans++;
		}
		if(A%key == 0){
			ans--;
		}
		System.out.println(B-A+1-ans);
		
		

	} 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 int C = sc.nextInt(); C sc.nextInt() sc.nextInt sc int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc long key = lcm(C, D); key lcm(C, D) lcm C D long ans = 0; ans 0 ans += (B/C - A/C) + (B/D - A/D) - (B/key - A/key) ans (B/C - A/C) + (B/D - A/D) - (B/key - A/key) (B/C - A/C) + (B/D - A/D) (B/C - A/C) B/C B C A/C A C (B/D - A/D) B/D B D A/D A D (B/key - A/key) B/key B key A/key A key if(A%C == 0){
			ans++;
		} A%C == 0 A%C A C 0 {
			ans++;
		} ans++ ans if(A%D == 0){
			ans++;
		} A%D == 0 A%D A D 0 {
			ans++;
		} ans++ ans if(A%key == 0){
			ans--;
		} A%key == 0 A%key A key 0 {
			ans--;
		} ans-- ans System.out.println(B-A+1-ans) System.out.println System.out System System.out B-A+1-ans B-A+1 B-A B A 1 ans String[] args args static int rsearch(int y,int x){

		int count = 0;
		while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		}
		return count;	

	} rsearch {

		int count = 0;
		while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		}
		return count;	

	} int count = 0; count 0 while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		} x < map[0].length && map[y][x] != '#' x < map[0].length x map[0].length map[0] map 0 map[0].length map[y][x] != '#' map[y][x] map[y] map y x '#' {
			count++;
			x++;
		} count++ count x++ x return count; count int y y int x x static int csearch(int y,int x){

		int count = 0;
		while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		}
		return count;	
	} csearch {

		int count = 0;
		while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		}
		return count;	
	} int count = 0; count 0 while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		} y < map.length && map[y][x] != '#' y < map.length y map.length map map.length map[y][x] != '#' map[y][x] map[y] map y x '#' {
			count++;
			y++;
		} count++ count y++ y return count; count int y y int x x static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){

		//		System.out.println("bit " + bit);

		for(int i = 0;i < m;i++){

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		}


		return true;

	} checkswitch {

		//		System.out.println("bit " + bit);

		for(int i = 0;i < m;i++){

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		}


		return true;

	} for(int i = 0;i < m;i++){

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		} {

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		} ArrayList<Integer> sub = list.get(i); sub list.get(i) list.get list i int onnum = 0; onnum 0 for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			} int j = 0; int j = 0; j 0 j < sub.size() j sub.size() sub.size sub j++ j++ j {
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			} {
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			} if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				} (bit & (1 << sub.get(j))) != 0 (bit & (1 << sub.get(j))) bit (1 << sub.get(j)) 1 sub.get(j) sub.get sub j 0 {				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				} onnum++ onnum if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			} onnum % 2 != p[i] onnum % 2 onnum 2 p[i] p i {				//一個でも電球がつかなかったらout
				return false;
			} return false; false return true; true int bit bit int[] k k ArrayList<ArrayList<Integer>> list list int[] p p int m m static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	} gcd {				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	} if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		} b == 0 b 0 {
			return a;
		} return a; a {
			return gcd(b, a%b);
		} return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b int a a int b b static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	} gcd {
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	} if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		} b == 0 b 0 {
			return a;
		} return a; a {
			return gcd(b, a%b);
		} return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b long a a long b b static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	} lcm {
		long g = gcd(a,b);
		return a/g*b;
	} long g = gcd(a,b); g gcd(a,b) gcd a b return a/g*b; a/g*b a/g a g b long a a long b b class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
} Pair int from; from int end; end @Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	} compareTo {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	} Pair otherpair = (Pair)other; otherpair (Pair)other return  otherpair.end - end; otherpair.end - end otherpair.end otherpair otherpair.end end Object other other Comparable
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static char[][] map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();

		long key = lcm(C, D);
//		System.out.println(key);
		long ans = 0;
		
		ans += (B/C - A/C) + (B/D - A/D) - (B/key - A/key);
//		System.out.println((B/C - A/C)+1);
//
//		System.out.println((B/D - A/D) + 1);
//		System.out.println((B/key - A/key)+1);


		if(A%C == 0){
			ans++;
		}
		if(A%D == 0){
			ans++;
		}
		if(A%key == 0){
			ans--;
		}
		System.out.println(B-A+1-ans);
		
		

	}

	static int rsearch(int y,int x){

		int count = 0;
		while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		}
		return count;	

	}

	static int csearch(int y,int x){

		int count = 0;
		while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		}
		return count;	
	}


	static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){

		//		System.out.println("bit " + bit);

		for(int i = 0;i < m;i++){

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		}


		return true;

	}

	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}


