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();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		System.out.println(sum);
	}

	public long gcd(long a,long b) {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%b,b);
	}
} 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();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		System.out.println(sum);
	}

	public long gcd(long a,long b) {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%b,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();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		System.out.println(sum);
	} main {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		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 long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc long sum = B-A+1; sum B-A+1 B-A B A 1 long maxC = B/C; maxC B/C B C long minC = A/C; minC A/C A C long maxD = B/D; maxD B/D B D long minD = A/D; minD A/D A D Main main = new Main(); main new Main() long gcd = main.gcd(C, D); gcd main.gcd(C, D) main.gcd main C D long maxCD = B/((C*D)/gcd); maxCD B/((C*D)/gcd) B ((C*D)/gcd) (C*D) C D gcd long minCD = A/((C*D)/gcd); minCD A/((C*D)/gcd) A ((C*D)/gcd) (C*D) C D gcd sum =sum -(maxC-minC) sum sum -(maxC-minC) sum (maxC-minC) maxC minC if (A%C==0) {
			sum--;
		} A%C==0 A%C A C 0 {
			sum--;
		} sum-- sum sum =sum -(maxD-minD) sum sum -(maxD-minD) sum (maxD-minD) maxD minD if (A%D==0) {
			sum--;
		} A%D==0 A%D A D 0 {
			sum--;
		} sum-- sum sum =sum +(maxCD-minCD) sum sum +(maxCD-minCD) sum (maxCD-minCD) maxCD minCD if (A%(((C*D)/gcd))==0) {
			sum++;
		} A%(((C*D)/gcd))==0 A%(((C*D)/gcd)) A (((C*D)/gcd)) (C*D) C D gcd 0 {
			sum++;
		} sum++ sum System.out.println(sum) System.out.println System.out System System.out sum String[] args args public long gcd(long a,long b) {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%b,b);
	} gcd {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%b,b);
	} if (a<b) {
			return gcd(b,a);
		} a<b a b {
			return gcd(b,a);
		} return gcd(b,a); gcd(b,a) gcd b a if (b==0) {
			return a;
		} b==0 b 0 {
			return a;
		} return a; a return gcd(a%b,b); gcd(a%b,b) gcd a%b a b 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();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		System.out.println(sum);
	}

	public long gcd(long a,long b) {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%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();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		System.out.println(sum);
	}

	public long gcd(long a,long b) {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%b,b);
	}
} 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();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		System.out.println(sum);
	}

	public long gcd(long a,long b) {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%b,b);
	}
}