import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(ans);
	}
	static long divider(long a, long b, long c){
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	}
	static long gcd(long c, long d){
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(ans);
	}
	static long divider(long a, long b, long c){
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	}
	static long gcd(long c, long d){
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(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 long c = sc.nextInt(); c sc.nextInt() sc.nextInt sc long d = sc.nextInt(); d sc.nextInt() sc.nextInt sc long gcd = gcd(c, d); gcd gcd(c, d) gcd c d long lcm = c * d / gcd; lcm c * d / gcd c * d c d gcd long divC = divider(a, b, c); divC divider(a, b, c) divider a b c long divD = divider(a, b, d); divD divider(a, b, d) divider a b d long divLcm = divider(a, b, lcm); divLcm divider(a, b, lcm) divider a b lcm long ans = b - a + 1 - divC - divD + divLcm; ans b - a + 1 - divC - divD + divLcm b - a + 1 - divC - divD b - a + 1 - divC - divD b - a + 1 b - a b a 1 divC divD divLcm System.out.println(ans) System.out.println System.out System System.out ans String[] args args static long divider(long a, long b, long c){
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	} divider {
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	} long divA = a / c; divA a / c a c long divB = b / c; divB b / c b c long modA = a % c; modA a % c a c long modB = b % c; modB b % c b c long ret = divB - divA; ret divB - divA divB divA if(modA == 0){
			ret++;
		} modA == 0 modA 0 {
			ret++;
		} ret++ ret return ret; ret long a a long b b long c c static long gcd(long c, long d){
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	} gcd {
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	} if(c > d){
			return gcd(d, c);
		} c > d c d {
			return gcd(d, c);
		} return gcd(d, c); gcd(d, c) gcd d c long mod = d % c; mod d % c d c if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		} mod == 0 mod 0 {
			return c;
		} return c; c {
			return gcd(mod, c);
		} return gcd(mod, c); gcd(mod, c) gcd mod c long c c long d d public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(ans);
	}
	static long divider(long a, long b, long c){
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	}
	static long gcd(long c, long d){
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(ans);
	}
	static long divider(long a, long b, long c){
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	}
	static long gcd(long c, long d){
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(ans);
	}
	static long divider(long a, long b, long c){
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	}
	static long gcd(long c, long d){
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	}
}
