import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    }

    public static long getGcd(long a, long b) {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    }

    public static long getGcd(long a, long b) {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()) - 1; a Long.parseLong(sc.next()) - 1 Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc 1 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 long gcd = (c * d) / getGcd(c, d); gcd (c * d) / getGcd(c, d) (c * d) c d getGcd(c, d) getGcd c d long bb = b - (b / c) - (b / d) + (b / gcd); bb b - (b / c) - (b / d) + (b / gcd) b - (b / c) - (b / d) b - (b / c) - (b / d) b (b / c) b c (b / d) b d (b / gcd) b gcd long aa = a - (a / c) - (a / d) + (a / gcd); aa a - (a / c) - (a / d) + (a / gcd) a - (a / c) - (a / d) a - (a / c) - (a / d) a (a / c) a c (a / d) a d (a / gcd) a gcd System.out.println(bb - aa) System.out.println System.out System System.out bb - aa bb aa String[] args args public static long getGcd(long a, long b) {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    } getGcd {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    } long tmp; tmp long x = 0; x 0 long y = 0; y 0 if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        } x >= y x y {
            x = a;
            y = b;
        } x = a x a y = b y b {
            x = b;
            y = a;
        } x = b x b y = a y a while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        } (tmp = x % y) != 0 (tmp = x % y) tmp x % y x y 0 {
            x = y;
            y = tmp;
        } x = y x y y = tmp y tmp return y; y long a a long b b public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    }

    public static long getGcd(long a, long b) {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    }

    public static long getGcd(long a, long b) {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    }

    public static long getGcd(long a, long b) {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }
}