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