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 under = A-1;
        long ans1 = B/C + B/D;
        long ans2 = (A-1)/C + (A-1)/D;
        long c = C;
        long d = D;
        while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        }
        long sm = C*D/c;
        long ans3 = B - (ans1 - B/sm);
        long ans4 = (A-1) - (ans2 - (A-1)/sm);
        System.out.println(ans3-ans4);
    }
} 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 under = A-1;
        long ans1 = B/C + B/D;
        long ans2 = (A-1)/C + (A-1)/D;
        long c = C;
        long d = D;
        while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        }
        long sm = C*D/c;
        long ans3 = B - (ans1 - B/sm);
        long ans4 = (A-1) - (ans2 - (A-1)/sm);
        System.out.println(ans3-ans4);
    }
} 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 under = A-1;
        long ans1 = B/C + B/D;
        long ans2 = (A-1)/C + (A-1)/D;
        long c = C;
        long d = D;
        while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        }
        long sm = C*D/c;
        long ans3 = B - (ans1 - B/sm);
        long ans4 = (A-1) - (ans2 - (A-1)/sm);
        System.out.println(ans3-ans4);
    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long under = A-1;
        long ans1 = B/C + B/D;
        long ans2 = (A-1)/C + (A-1)/D;
        long c = C;
        long d = D;
        while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        }
        long sm = C*D/c;
        long ans3 = B - (ans1 - B/sm);
        long ans4 = (A-1) - (ans2 - (A-1)/sm);
        System.out.println(ans3-ans4);
    } 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 under = A-1; under A-1 A 1 long ans1 = B/C + B/D; ans1 B/C + B/D B/C B C B/D B D long ans2 = (A-1)/C + (A-1)/D; ans2 (A-1)/C + (A-1)/D (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D long c = C; c C long d = D; d D while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        } true {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        } long tmp = c%d; tmp c%d c d c = d c d d = tmp d tmp if (d == 0) {
                break;
            } d == 0 d 0 {
                break;
            } break; long sm = C*D/c; sm C*D/c C*D C D c long ans3 = B - (ans1 - B/sm); ans3 B - (ans1 - B/sm) B (ans1 - B/sm) ans1 B/sm B sm long ans4 = (A-1) - (ans2 - (A-1)/sm); ans4 (A-1) - (ans2 - (A-1)/sm) (A-1) A 1 (ans2 - (A-1)/sm) ans2 (A-1)/sm (A-1) A 1 sm System.out.println(ans3-ans4) System.out.println System.out System System.out ans3-ans4 ans3 ans4 String[] args args 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 under = A-1;
        long ans1 = B/C + B/D;
        long ans2 = (A-1)/C + (A-1)/D;
        long c = C;
        long d = D;
        while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        }
        long sm = C*D/c;
        long ans3 = B - (ans1 - B/sm);
        long ans4 = (A-1) - (ans2 - (A-1)/sm);
        System.out.println(ans3-ans4);
    }
} 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 under = A-1;
        long ans1 = B/C + B/D;
        long ans2 = (A-1)/C + (A-1)/D;
        long c = C;
        long d = D;
        while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        }
        long sm = C*D/c;
        long ans3 = B - (ans1 - B/sm);
        long ans4 = (A-1) - (ans2 - (A-1)/sm);
        System.out.println(ans3-ans4);
    }
} 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 under = A-1;
        long ans1 = B/C + B/D;
        long ans2 = (A-1)/C + (A-1)/D;
        long c = C;
        long d = D;
        while (true) {
            long tmp = c%d;
            c = d;
            d = tmp;
            if (d == 0) {
                break;
            }
        }
        long sm = C*D/c;
        long ans3 = B - (ans1 - B/sm);
        long ans4 = (A-1) - (ans2 - (A-1)/sm);
        System.out.println(ans3-ans4);
    }
}