

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();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    }

    static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    // cでもdでも割れない個数
    static long num(long n, long c, long d) {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    }
} 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();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    }

    static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    // cでもdでも割れない個数
    static long num(long n, long c, long d) {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    }
} 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();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    } 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 System.out.println(num(B,C,D) - num(A-1,C,D)) System.out.println System.out System System.out num(B,C,D) - num(A-1,C,D) num(B,C,D) num B C D num(A-1,C,D) num A-1 A 1 C D String[] args args static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    } gcd {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    } if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        } b == 0 b 0 {
            return a;
        } return a; a {
            return gcd(b, a % b);
        } return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b // cでもdでも割れない個数
    static long num(long n, long c, long d) {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    } num {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    } long G = gcd(c,d); G gcd(c,d) gcd c d long L = c / G * d; L c / G * d c / G c G d return n - (n/c) - (n/d) + (n/L); n - (n/c) - (n/d) + (n/L) n - (n/c) - (n/d) n - (n/c) - (n/d) n (n/c) n c (n/d) n d (n/L) n L long n n long c c long d d 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();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    }

    static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    // cでもdでも割れない個数
    static long num(long n, long c, long d) {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    }
} 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();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    }

    static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    // cでもdでも割れない個数
    static long num(long n, long c, long d) {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    }
} 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();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    }

    static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    // cでもdでも割れない個数
    static long num(long n, long c, long d) {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    }
}
