import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[][] dp;
    int MAX_M = 100000;
    int MAX_N = 100000;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        A--;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long c = (B/C) - (A/C);
        long D = sc.nextLong();
        long d = (B/D) - (A/D);
        long L = lcm(C,D);
        long l = (B/L) - (A/L);
        System.out.println((B-A)-c-d+l);

    }
    static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
}
} import java.util.*; util.* java public class Main {

    long INF = Long.MAX_VALUE;
    long[][] dp;
    int MAX_M = 100000;
    int MAX_N = 100000;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        A--;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long c = (B/C) - (A/C);
        long D = sc.nextLong();
        long d = (B/D) - (A/D);
        long L = lcm(C,D);
        long l = (B/L) - (A/L);
        System.out.println((B-A)-c-d+l);

    }
    static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
}
} Main long INF = Long.MAX_VALUE; INF Long.MAX_VALUE Long Long.MAX_VALUE long[][] dp; dp int MAX_M = 100000; MAX_M 100000 int MAX_N = 100000; MAX_N 100000 public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        A--;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long c = (B/C) - (A/C);
        long D = sc.nextLong();
        long d = (B/D) - (A/D);
        long L = lcm(C,D);
        long l = (B/L) - (A/L);
        System.out.println((B-A)-c-d+l);

    } solve {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        A--;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long c = (B/C) - (A/C);
        long D = sc.nextLong();
        long d = (B/D) - (A/D);
        long L = lcm(C,D);
        long l = (B/L) - (A/L);
        System.out.println((B-A)-c-d+l);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = sc.nextLong(); A sc.nextLong() sc.nextLong sc A-- A long B = sc.nextLong(); B sc.nextLong() sc.nextLong sc long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc long c = (B/C) - (A/C); c (B/C) - (A/C) (B/C) B C (A/C) A C long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc long d = (B/D) - (A/D); d (B/D) - (A/D) (B/D) B D (A/D) A D long L = lcm(C,D); L lcm(C,D) lcm C D long l = (B/L) - (A/L); l (B/L) - (A/L) (B/L) B L (A/L) A L System.out.println((B-A)-c-d+l) System.out.println System.out System System.out (B-A)-c-d+l (B-A)-c-d (B-A)-c-d (B-A) B A c d l static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
} lcm {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
} long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
		a = b;
		b = temp;
	} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
		a = b;
		b = temp;
	} a = b a b b = temp b temp return (c/b); (c/b) c b long a a long b b public class Main {

    long INF = Long.MAX_VALUE;
    long[][] dp;
    int MAX_M = 100000;
    int MAX_N = 100000;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        A--;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long c = (B/C) - (A/C);
        long D = sc.nextLong();
        long d = (B/D) - (A/D);
        long L = lcm(C,D);
        long l = (B/L) - (A/L);
        System.out.println((B-A)-c-d+l);

    }
    static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
}
} public class Main {

    long INF = Long.MAX_VALUE;
    long[][] dp;
    int MAX_M = 100000;
    int MAX_N = 100000;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        A--;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long c = (B/C) - (A/C);
        long D = sc.nextLong();
        long d = (B/D) - (A/D);
        long L = lcm(C,D);
        long l = (B/L) - (A/L);
        System.out.println((B-A)-c-d+l);

    }
    static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
}
} Main
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[][] dp;
    int MAX_M = 100000;
    int MAX_N = 100000;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        A--;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long c = (B/C) - (A/C);
        long D = sc.nextLong();
        long d = (B/D) - (A/D);
        long L = lcm(C,D);
        long l = (B/L) - (A/L);
        System.out.println((B-A)-c-d+l);

    }
    static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
}
}