import java.util.Scanner;
public class Main {

//最小公倍数lcm
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 static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		/*long cnt = 0;
		for(long i = a; i <= b; i++) {
			if(i%c!=0 && i%d != 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
		
		*/
		
		long acnt = b/c; //cで割り切れる数
		long bcnt = b/d;
		long l = lcm(c,d);
		long abcnt = b/l;
		
		long atemp = (a-1)/c;
		long btemp = (a-1)/d;
		long abtemp = (a-1)/l;
		
		long atmp = acnt-atemp;
		long btmp = bcnt-btemp;
		long abtmp = abcnt - abtemp;
		
		long ans = (b-a+1)-(atmp+btmp-abtmp);
		System.out.println(ans);
	}

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

//最小公倍数lcm
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 static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		/*long cnt = 0;
		for(long i = a; i <= b; i++) {
			if(i%c!=0 && i%d != 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
		
		*/
		
		long acnt = b/c; //cで割り切れる数
		long bcnt = b/d;
		long l = lcm(c,d);
		long abcnt = b/l;
		
		long atemp = (a-1)/c;
		long btemp = (a-1)/d;
		long abtemp = (a-1)/l;
		
		long atmp = acnt-atemp;
		long btmp = bcnt-btemp;
		long abtmp = abcnt - abtemp;
		
		long ans = (b-a+1)-(atmp+btmp-abtmp);
		System.out.println(ans);
	}

} Main //最小公倍数lcm
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 static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		/*long cnt = 0;
		for(long i = a; i <= b; i++) {
			if(i%c!=0 && i%d != 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
		
		*/
		
		long acnt = b/c; //cで割り切れる数
		long bcnt = b/d;
		long l = lcm(c,d);
		long abcnt = b/l;
		
		long atemp = (a-1)/c;
		long btemp = (a-1)/d;
		long abtemp = (a-1)/l;
		
		long atmp = acnt-atemp;
		long btmp = bcnt-btemp;
		long abtmp = abcnt - abtemp;
		
		long ans = (b-a+1)-(atmp+btmp-abtmp);
		System.out.println(ans);
	} main {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		/*long cnt = 0;
		for(long i = a; i <= b; i++) {
			if(i%c!=0 && i%d != 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
		
		*/
		
		long acnt = b/c; //cで割り切れる数
		long bcnt = b/d;
		long l = lcm(c,d);
		long abcnt = b/l;
		
		long atemp = (a-1)/c;
		long btemp = (a-1)/d;
		long abtemp = (a-1)/l;
		
		long atmp = acnt-atemp;
		long btmp = bcnt-btemp;
		long abtmp = abcnt - abtemp;
		
		long ans = (b-a+1)-(atmp+btmp-abtmp);
		System.out.println(ans);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) long a = stdIn.nextLong(); a stdIn.nextLong() stdIn.nextLong stdIn long b = stdIn.nextLong(); b stdIn.nextLong() stdIn.nextLong stdIn long c = stdIn.nextLong(); c stdIn.nextLong() stdIn.nextLong stdIn long d = stdIn.nextLong(); d stdIn.nextLong() stdIn.nextLong stdIn long acnt = b/c; acnt b/c b c long bcnt = b/d; bcnt b/d b d long l = lcm(c,d); l lcm(c,d) lcm c d long abcnt = b/l; abcnt b/l b l long atemp = (a-1)/c; atemp (a-1)/c (a-1) a 1 c long btemp = (a-1)/d; btemp (a-1)/d (a-1) a 1 d long abtemp = (a-1)/l; abtemp (a-1)/l (a-1) a 1 l long atmp = acnt-atemp; atmp acnt-atemp acnt atemp long btmp = bcnt-btemp; btmp bcnt-btemp bcnt btemp long abtmp = abcnt - abtemp; abtmp abcnt - abtemp abcnt abtemp long ans = (b-a+1)-(atmp+btmp-abtmp); ans (b-a+1)-(atmp+btmp-abtmp) (b-a+1) b-a b a 1 (atmp+btmp-abtmp) atmp+btmp atmp btmp abtmp System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

//最小公倍数lcm
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 static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		/*long cnt = 0;
		for(long i = a; i <= b; i++) {
			if(i%c!=0 && i%d != 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
		
		*/
		
		long acnt = b/c; //cで割り切れる数
		long bcnt = b/d;
		long l = lcm(c,d);
		long abcnt = b/l;
		
		long atemp = (a-1)/c;
		long btemp = (a-1)/d;
		long abtemp = (a-1)/l;
		
		long atmp = acnt-atemp;
		long btmp = bcnt-btemp;
		long abtmp = abcnt - abtemp;
		
		long ans = (b-a+1)-(atmp+btmp-abtmp);
		System.out.println(ans);
	}

} public class Main {

//最小公倍数lcm
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 static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		/*long cnt = 0;
		for(long i = a; i <= b; i++) {
			if(i%c!=0 && i%d != 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
		
		*/
		
		long acnt = b/c; //cで割り切れる数
		long bcnt = b/d;
		long l = lcm(c,d);
		long abcnt = b/l;
		
		long atemp = (a-1)/c;
		long btemp = (a-1)/d;
		long abtemp = (a-1)/l;
		
		long atmp = acnt-atemp;
		long btmp = bcnt-btemp;
		long abtmp = abcnt - abtemp;
		
		long ans = (b-a+1)-(atmp+btmp-abtmp);
		System.out.println(ans);
	}

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

//最小公倍数lcm
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 static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		/*long cnt = 0;
		for(long i = a; i <= b; i++) {
			if(i%c!=0 && i%d != 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
		
		*/
		
		long acnt = b/c; //cで割り切れる数
		long bcnt = b/d;
		long l = lcm(c,d);
		long abcnt = b/l;
		
		long atemp = (a-1)/c;
		long btemp = (a-1)/d;
		long abtemp = (a-1)/l;
		
		long atmp = acnt-atemp;
		long btmp = bcnt-btemp;
		long abtmp = abcnt - abtemp;
		
		long ans = (b-a+1)-(atmp+btmp-abtmp);
		System.out.println(ans);
	}

}
