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 = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		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 = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		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 = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		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 = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		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 cnt = b-b/c-b/d+b/lcm(c,d); cnt b-b/c-b/d+b/lcm(c,d) b-b/c-b/d b-b/c-b/d b b/c b c b/d b d b/lcm(c,d) b lcm(c,d) lcm c d long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d); ccnt (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d) (a-1)-(a-1)/c-(a-1)/d (a-1)-(a-1)/c-(a-1)/d (a-1) a 1 (a-1)/c (a-1) a 1 c (a-1)/d (a-1) a 1 d (a-1)/lcm(c,d) (a-1) a 1 lcm(c,d) lcm c d long ans = cnt - ccnt; ans cnt - ccnt cnt ccnt 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 = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		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 = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		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 = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		System.out.println(ans);
		
	}

}
