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();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long bdivic = B / C;
		long bdivid = B / D;
		long adivic = (A - 1) / C;
		long adivid = (A - 1) / D;
		long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid);
		sum += B / lcm(C, D) - (A - 1)  / lcm(C, D);
		System.out.println(sum);


	}

	//最小公約数を求める
	public static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	//最大公約数を求める　ユークリッドの互除法
	public static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}


} 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();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long bdivic = B / C;
		long bdivid = B / D;
		long adivic = (A - 1) / C;
		long adivid = (A - 1) / D;
		long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid);
		sum += B / lcm(C, D) - (A - 1)  / lcm(C, D);
		System.out.println(sum);


	}

	//最小公約数を求める
	public static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	//最大公約数を求める　ユークリッドの互除法
	public static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}


} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long bdivic = B / C;
		long bdivid = B / D;
		long adivic = (A - 1) / C;
		long adivid = (A - 1) / D;
		long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid);
		sum += B / lcm(C, D) - (A - 1)  / lcm(C, D);
		System.out.println(sum);


	} main {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long bdivic = B / C;
		long bdivid = B / D;
		long adivic = (A - 1) / C;
		long adivid = (A - 1) / D;
		long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid);
		sum += B / lcm(C, D) - (A - 1)  / lcm(C, D);
		System.out.println(sum);


	} 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 int C = sc.nextInt(); C sc.nextInt() sc.nextInt sc int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc long bdivic = B / C; bdivic B / C B C long bdivid = B / D; bdivid B / D B D long adivic = (A - 1) / C; adivic (A - 1) / C (A - 1) A 1 C long adivid = (A - 1) / D; adivid (A - 1) / D (A - 1) A 1 D long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid); sum B - (A - 1) - (bdivic - adivic) - (bdivid - adivid) (bdivic - adivic) B - (A - 1) - (bdivic - adivic) - (bdivid - adivid) B (A - 1) A 1 (bdivic - adivic) bdivic adivic (bdivid - adivid) bdivid adivid sum += B / lcm(C, D) - (A - 1)  / lcm(C, D) sum B / lcm(C, D) - (A - 1)  / lcm(C, D) B / lcm(C, D) B lcm(C, D) lcm C D (A - 1)  / lcm(C, D) (A - 1) A 1 lcm(C, D) lcm C D System.out.println(sum) System.out.println System.out System System.out sum String[] args args //最小公約数を求める
	public static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	} lcm {
	    return m * n / gcd(m, n);
	} return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n //最大公約数を求める　ユークリッドの互除法
	public static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	} gcd {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	} if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long bdivic = B / C;
		long bdivid = B / D;
		long adivic = (A - 1) / C;
		long adivid = (A - 1) / D;
		long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid);
		sum += B / lcm(C, D) - (A - 1)  / lcm(C, D);
		System.out.println(sum);


	}

	//最小公約数を求める
	public static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	//最大公約数を求める　ユークリッドの互除法
	public static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}


} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long bdivic = B / C;
		long bdivid = B / D;
		long adivic = (A - 1) / C;
		long adivid = (A - 1) / D;
		long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid);
		sum += B / lcm(C, D) - (A - 1)  / lcm(C, D);
		System.out.println(sum);


	}

	//最小公約数を求める
	public static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	//最大公約数を求める　ユークリッドの互除法
	public static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}


} 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();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long bdivic = B / C;
		long bdivid = B / D;
		long adivic = (A - 1) / C;
		long adivid = (A - 1) / D;
		long sum = B - (A - 1) - (bdivic - adivic) - (bdivid - adivid);
		sum += B / lcm(C, D) - (A - 1)  / lcm(C, D);
		System.out.println(sum);


	}

	//最小公約数を求める
	public static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	//最大公約数を求める　ユークリッドの互除法
	public static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}


}
