import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	}
	
	private static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	}
	
	private static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A A B B C C D; D A = Long.parseLong(sc.next()) - 1 A Long.parseLong(sc.next()) - 1 Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc 1 B = Long.parseLong(sc.next()) B Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc C = Long.parseLong(sc.next()) C Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc D = Long.parseLong(sc.next()) D Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc int count = 0; count 0 long lcm = C * D / gcd(C, D); lcm C * D / gcd(C, D) C * D C D gcd(C, D) gcd C D long tmpAC = A / C; tmpAC A / C A C long tmpBC = B / C; tmpBC B / C B C long tmpAD = A / D; tmpAD A / D A D long tmpBD = B / D; tmpBD B / D B D long tmpACD = A / lcm; tmpACD A / lcm A lcm long tmpBCD = B / lcm; tmpBCD B / lcm B lcm long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD); ans tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD) tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD) tmpBC - tmpAC + tmpBD tmpBC - tmpAC tmpBC tmpAC tmpBD tmpAD (tmpBCD - tmpACD) tmpBCD tmpACD ans = B - (A + 1) + 1 - ans ans B - (A + 1) + 1 - ans B - (A + 1) + 1 B - (A + 1) B (A + 1) A 1 1 ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	} gcd {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	} long tmp; tmp while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		} m % n != 0 m % n m n 0 {
			tmp = n;
			n = m % n;
			m = tmp;
		} tmp = n tmp n n = m % n n m % n m n m = tmp m tmp return n; n long m m long n n public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	}
	
	private static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	}
	
	private static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	}
	
	private static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}

}
