import 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.nextLong();
		long d = sc.nextLong();
		System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)));
	}
	static long div(long x, long y, long z){
		return y / z - (x-1) / z;
	}
	static long gcd(long a, long b){
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	}
} import java.util.*; util.* java 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.nextLong();
		long d = sc.nextLong();
		System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)));
	}
	static long div(long x, long y, long z){
		return y / z - (x-1) / z;
	}
	static long gcd(long a, long b){
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)));
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)));
	} 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.nextLong(); c sc.nextLong() sc.nextLong sc long d = sc.nextLong(); d sc.nextLong() sc.nextLong sc System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d))) System.out.println System.out System System.out b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)) b-a+1 - div(a,b,c) - div(a,b,d) b-a+1 - div(a,b,c) - div(a,b,d) b-a+1 b-a b a 1 div(a,b,c) div a b c div(a,b,d) div a b d div(a,b,c*d/gcd(c,d)) div a b c*d/gcd(c,d) c*d c d gcd(c,d) gcd c d String[] args args static long div(long x, long y, long z){
		return y / z - (x-1) / z;
	} div {
		return y / z - (x-1) / z;
	} return y / z - (x-1) / z; y / z - (x-1) / z y / z y z (x-1) / z (x-1) x 1 z long x x long y y long z z static long gcd(long a, long b){
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	} gcd {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	} if(a < b) return gcd(b, a); a < b a b return gcd(b, a); gcd(b, a) gcd b a if(b == 0) return a;
		else return gcd(b, a % b); b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b 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.nextLong();
		long d = sc.nextLong();
		System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)));
	}
	static long div(long x, long y, long z){
		return y / z - (x-1) / z;
	}
	static long gcd(long a, long b){
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	}
} 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.nextLong();
		long d = sc.nextLong();
		System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)));
	}
	static long div(long x, long y, long z){
		return y / z - (x-1) / z;
	}
	static long gcd(long a, long b){
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	}
} Main
import 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.nextLong();
		long d = sc.nextLong();
		System.out.println(b-a+1 - div(a,b,c) - div(a,b,d) + div(a,b,c*d/gcd(c,d)));
	}
	static long div(long x, long y, long z){
		return y / z - (x-1) / z;
	}
	static long gcd(long a, long b){
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	}
}
