import java.util.Scanner;

public class Main {

	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 static long lcm(long m,long n) {
		return m * n / gcd(m ,n);
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	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 static long lcm(long m,long n) {
		return m * n / gcd(m ,n);
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	}
} Main 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 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 void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	} main {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Long A = Long.parseLong(sc.next()); A Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc Long B = Long.parseLong(sc.next()); B Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc Long C = Long.parseLong(sc.next()); C Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc Long D = Long.parseLong(sc.next()); D Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc sc.close() sc.close sc long x = A / C; x A / C A C long y = B / C; y B / C B C long numberC = 0; numberC 0 if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		} (A % C == 0) && (B % C == 0) (A % C == 0) A % C A C 0 (B % C == 0) B % C B C 0 {
			numberC = y - x + 1;
		} numberC = y - x + 1 numberC y - x + 1 y - x y x 1 if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		} A % C == 0 A % C A C 0 {
			numberC = y - x + 1;
		} numberC = y - x + 1 numberC y - x + 1 y - x y x 1 if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		} B % C == 0 B % C B C 0 {
			numberC = y - x;
		} numberC = y - x numberC y - x y x {
			numberC = y - x;
		} numberC = y - x numberC y - x y x long p = A / D; p A / D A D long q = B / D; q B / D B D long numberD = 0; numberD 0 if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		} (A % D == 0) & (B % D == 0) (A % D == 0) A % D A D 0 (B % D == 0) B % D B D 0 {
			numberD = q - p + 1;
		} numberD = q - p + 1 numberD q - p + 1 q - p q p 1 if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		} A % D == 0 A % D A D 0 {
			numberD = q - p + 1;
		} numberD = q - p + 1 numberD q - p + 1 q - p q p 1 if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		} B % D == 0 B % D B D 0 {
			numberD = q - p;
		} numberD = q - p numberD q - p q p {
			numberD = q - p;
		} numberD = q - p numberD q - p q p long E = lcm(C ,D); E lcm(C ,D) lcm C D long s = B / E; s B / E B E long t = A / E; t A / E A E long numberE = 0; numberE 0 if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		} (A % E == 0)&& (B % E == 0) (A % E == 0) A % E A E 0 (B % E == 0) B % E B E 0 {
			numberE = s - t + 1;
		} numberE = s - t + 1 numberE s - t + 1 s - t s t 1 if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		} A % E == 0 A % E A E 0 {
			numberE = s - t + 1;
		} numberE = s - t + 1 numberE s - t + 1 s - t s t 1 if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		} B % E == 0 B % E B E 0 {
			numberE = s - t;
		} numberE = s - t numberE s - t s t {
			numberE = s - t;
		} numberE = s - t numberE s - t s t long result = numberC + numberD - numberE; result numberC + numberD - numberE numberC + numberD numberC numberD numberE long answer = B - A + 1 -result; answer B - A + 1 -result B - A + 1 B - A B A 1 result System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	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 static long lcm(long m,long n) {
		return m * n / gcd(m ,n);
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	}
} public class Main {

	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 static long lcm(long m,long n) {
		return m * n / gcd(m ,n);
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	}
} Main
import java.util.Scanner;

public class Main {

	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 static long lcm(long m,long n) {
		return m * n / gcd(m ,n);
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A = Long.parseLong(sc.next());
		Long B = Long.parseLong(sc.next());
		Long C = Long.parseLong(sc.next());
		Long D = Long.parseLong(sc.next());
		sc.close();

		long x = A / C;
		long y = B / C;
		long numberC = 0;
		if((A % C == 0) && (B % C == 0)) {
			numberC = y - x + 1;
		}else if(A % C == 0){
			numberC = y - x + 1;
		}else if(B % C == 0) {
			numberC = y - x;
		}else {
			numberC = y - x;
		}

		long p = A / D;
		long q = B / D;
		long numberD = 0;
		if((A % D == 0) & (B % D == 0)) {
			numberD = q - p + 1;
		}else if(A % D == 0){
			numberD = q - p + 1;
		}else if(B % D == 0) {
			numberD = q - p;
		}else {
			numberD = q - p;
		}

		long E = lcm(C ,D);
		long s = B / E;
		long t = A / E;
		long numberE = 0;
		if((A % E == 0)&& (B % E == 0)) {
			numberE = s - t + 1;
		}else if(A % E == 0){
			numberE = s - t + 1;
		}else if(B % E == 0) {
			numberE = s - t;
		}else {
			numberE = s - t;
		}

		long result = numberC + numberD - numberE;
		long answer = B - A + 1 -result;
		System.out.println(answer);
	}
}
