import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		}
		
		
	}
	
	
	
	private  static long lcm(long A,long B) {//最小公倍数
		return A*B/gcd(A,B);
	}
	
	private static long gcd(long A,long B){//最大公約数
		return B==0?A:gcd (B,A%B);
	}
		

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		}
		
		
	}
	
	
	
	private  static long lcm(long A,long B) {//最小公倍数
		return A*B/gcd(A,B);
	}
	
	private static long gcd(long A,long B){//最大公約数
		return B==0?A:gcd (B,A%B);
	}
		

} Main public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		}
		
		
	} main {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		}
		
		
	} try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		} {
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		} Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) long A = scan.nextLong(); A scan.nextLong() scan.nextLong scan long B = scan.nextLong(); B scan.nextLong() scan.nextLong scan long C = scan.nextLong(); C scan.nextLong() scan.nextLong scan long D = scan.nextLong(); D scan.nextLong() scan.nextLong scan long bc = B/C; bc B/C B C long bd = B/D; bd B/D B D long bcd = B/lcm(C,D); bcd B/lcm(C,D) B lcm(C,D) lcm C D long ac = A/C; ac A/C A C long ad = A/D; ad A/D A D long acd =A/lcm(C,D); acd A/lcm(C,D) A lcm(C,D) lcm C D long Bwari = B-bc-bd+bcd; Bwari B-bc-bd+bcd B-bc-bd B-bc-bd B bc bd bcd long Awari = A-ac-ad+acd; Awari A-ac-ad+acd A-ac-ad A-ac-ad A ac ad acd if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			} A%C!=0&&A%D!=0 A%C!=0 A%C A C 0 A%D!=0 A%D A D 0 {
				System.out.println(Bwari-Awari+1);
			} System.out.println(Bwari-Awari+1) System.out.println System.out System System.out Bwari-Awari+1 Bwari-Awari Bwari Awari 1 {
				System.out.println(Bwari-Awari);
			} System.out.println(Bwari-Awari) System.out.println System.out System System.out Bwari-Awari Bwari Awari String[]args args private  static long lcm(long A,long B) {//最小公倍数
		return A*B/gcd(A,B);
	} lcm {//最小公倍数
		return A*B/gcd(A,B);
	} return A*B/gcd(A,B); A*B/gcd(A,B) A*B A B gcd(A,B) gcd A B long A A long B B private static long gcd(long A,long B){//最大公約数
		return B==0?A:gcd (B,A%B);
	} gcd {//最大公約数
		return B==0?A:gcd (B,A%B);
	} return B==0?A:gcd (B,A%B); B==0?A:gcd (B,A%B) B==0 B 0 A 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) {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		}
		
		
	}
	
	
	
	private  static long lcm(long A,long B) {//最小公倍数
		return A*B/gcd(A,B);
	}
	
	private static long gcd(long A,long B){//最大公約数
		return B==0?A:gcd (B,A%B);
	}
		

} public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		}
		
		
	}
	
	
	
	private  static long lcm(long A,long B) {//最小公倍数
		return A*B/gcd(A,B);
	}
	
	private static long gcd(long A,long B){//最大公約数
		return B==0?A:gcd (B,A%B);
	}
		

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B = scan.nextLong();
			long C = scan.nextLong();
			long D = scan.nextLong();
			
			long bc = B/C;
			long bd = B/D;
			long bcd = B/lcm(C,D);
			
			long ac = A/C;
			long ad = A/D;
			long acd =A/lcm(C,D);
			
			long Bwari = B-bc-bd+bcd;
			long Awari = A-ac-ad+acd;
			
			if(A%C!=0&&A%D!=0) {
				System.out.println(Bwari-Awari+1);
			}else {
				System.out.println(Bwari-Awari);
			}
			
			
			
		}
		
		
	}
	
	
	
	private  static long lcm(long A,long B) {//最小公倍数
		return A*B/gcd(A,B);
	}
	
	private static long gcd(long A,long B){//最大公約数
		return B==0?A:gcd (B,A%B);
	}
		

}
