import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long C;
        C = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B, C, D);
    }
}

class Solver {
    public void solve(long A, long B, long C, long D) {
        long top = num(B, C, D);
        long bottom = num(A - 1, C, D);
        long ans = top - bottom;

        System.out.println(ans);
    }

    private long num(long N, long C, long D) {
        long lcd = Math.abs(C * D) / gcd(C, D);
        return N - (N / C + N / D - N / lcd);
    }

    private long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long C;
        C = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B, C, D);
    }
} Main public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long C;
        C = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B, C, D);
    } main {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long C;
        C = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B, C, D);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A; A A = sc.nextLong() A sc.nextLong() sc.nextLong sc long B; B B = sc.nextLong() B sc.nextLong() sc.nextLong sc long C; C C = sc.nextLong() C sc.nextLong() sc.nextLong sc long D; D D = sc.nextLong() D sc.nextLong() sc.nextLong sc final Solver solver = new Solver(); solver new Solver() solver.solve(A, B, C, D) solver.solve solver A B C D final String[] args args class Solver {
    public void solve(long A, long B, long C, long D) {
        long top = num(B, C, D);
        long bottom = num(A - 1, C, D);
        long ans = top - bottom;

        System.out.println(ans);
    }

    private long num(long N, long C, long D) {
        long lcd = Math.abs(C * D) / gcd(C, D);
        return N - (N / C + N / D - N / lcd);
    }

    private long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }
} Solver public void solve(long A, long B, long C, long D) {
        long top = num(B, C, D);
        long bottom = num(A - 1, C, D);
        long ans = top - bottom;

        System.out.println(ans);
    } solve {
        long top = num(B, C, D);
        long bottom = num(A - 1, C, D);
        long ans = top - bottom;

        System.out.println(ans);
    } long top = num(B, C, D); top num(B, C, D) num B C D long bottom = num(A - 1, C, D); bottom num(A - 1, C, D) num A - 1 A 1 C D long ans = top - bottom; ans top - bottom top bottom System.out.println(ans) System.out.println System.out System System.out ans long A A long B B long C C long D D private long num(long N, long C, long D) {
        long lcd = Math.abs(C * D) / gcd(C, D);
        return N - (N / C + N / D - N / lcd);
    } num {
        long lcd = Math.abs(C * D) / gcd(C, D);
        return N - (N / C + N / D - N / lcd);
    } long lcd = Math.abs(C * D) / gcd(C, D); lcd Math.abs(C * D) / gcd(C, D) Math.abs(C * D) Math.abs Math C * D C D gcd(C, D) gcd C D return N - (N / C + N / D - N / lcd); N - (N / C + N / D - N / lcd) N (N / C + N / D - N / lcd) N / C + N / D N / C N C N / D N D N / lcd N lcd long N N long C C long D D private 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(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long C;
        C = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B, C, D);
    }
} public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long C;
        C = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B, C, D);
    }
} Main
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long C;
        C = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B, C, D);
    }
}

class Solver {
    public void solve(long A, long B, long C, long D) {
        long top = num(B, C, D);
        long bottom = num(A - 1, C, D);
        long ans = top - bottom;

        System.out.println(ans);
    }

    private long num(long N, long C, long D) {
        long lcd = Math.abs(C * D) / gcd(C, D);
        return N - (N / C + N / D - N / lcd);
    }

    private long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }
}
