
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();
        sc.close();

        /** だめだったその１**/
        //        long result = LongStream.rangeClosed(A, B)
        //                .filter(i-> i%C!=0)
        //                .filter(i-> i%D!=0)
        //                .count();
        //        
        //        System.out.println(result);

        /** だめだったその２**/
        //        long resultNoHantai = LongStream.rangeClosed(A, B)
        //                .filter(i -> i % C == 0 || i % D == 0)
        //                .count();
        //
        //        long result = B - A + 1L - resultNoHantai;
        //        System.out.println(result);

        long wareruC = B / C - A / C;
        if (A % C == 0L)
            wareruC++;

        long wareruD = B / D - A / D;
        if (A % D == 0L)
            wareruD++;

        long saisyoukoubaisuu = lcm(C, D);

        long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu;
        if (A % saisyoukoubaisuu == 0L)
            wareruCD++;

        long result = (B - A + 1L) - wareruC - wareruD + wareruCD;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    }
} 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();
        sc.close();

        /** だめだったその１**/
        //        long result = LongStream.rangeClosed(A, B)
        //                .filter(i-> i%C!=0)
        //                .filter(i-> i%D!=0)
        //                .count();
        //        
        //        System.out.println(result);

        /** だめだったその２**/
        //        long resultNoHantai = LongStream.rangeClosed(A, B)
        //                .filter(i -> i % C == 0 || i % D == 0)
        //                .count();
        //
        //        long result = B - A + 1L - resultNoHantai;
        //        System.out.println(result);

        long wareruC = B / C - A / C;
        if (A % C == 0L)
            wareruC++;

        long wareruD = B / D - A / D;
        if (A % D == 0L)
            wareruD++;

        long saisyoukoubaisuu = lcm(C, D);

        long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu;
        if (A % saisyoukoubaisuu == 0L)
            wareruCD++;

        long result = (B - A + 1L) - wareruC - wareruD + wareruCD;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    }
} 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();
        sc.close();

        /** だめだったその１**/
        //        long result = LongStream.rangeClosed(A, B)
        //                .filter(i-> i%C!=0)
        //                .filter(i-> i%D!=0)
        //                .count();
        //        
        //        System.out.println(result);

        /** だめだったその２**/
        //        long resultNoHantai = LongStream.rangeClosed(A, B)
        //                .filter(i -> i % C == 0 || i % D == 0)
        //                .count();
        //
        //        long result = B - A + 1L - resultNoHantai;
        //        System.out.println(result);

        long wareruC = B / C - A / C;
        if (A % C == 0L)
            wareruC++;

        long wareruD = B / D - A / D;
        if (A % D == 0L)
            wareruD++;

        long saisyoukoubaisuu = lcm(C, D);

        long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu;
        if (A % saisyoukoubaisuu == 0L)
            wareruCD++;

        long result = (B - A + 1L) - wareruC - wareruD + wareruCD;

        System.out.println(result);

    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        sc.close();

        /** だめだったその１**/
        //        long result = LongStream.rangeClosed(A, B)
        //                .filter(i-> i%C!=0)
        //                .filter(i-> i%D!=0)
        //                .count();
        //        
        //        System.out.println(result);

        /** だめだったその２**/
        //        long resultNoHantai = LongStream.rangeClosed(A, B)
        //                .filter(i -> i % C == 0 || i % D == 0)
        //                .count();
        //
        //        long result = B - A + 1L - resultNoHantai;
        //        System.out.println(result);

        long wareruC = B / C - A / C;
        if (A % C == 0L)
            wareruC++;

        long wareruD = B / D - A / D;
        if (A % D == 0L)
            wareruD++;

        long saisyoukoubaisuu = lcm(C, D);

        long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu;
        if (A % saisyoukoubaisuu == 0L)
            wareruCD++;

        long result = (B - A + 1L) - wareruC - wareruD + wareruCD;

        System.out.println(result);

    } 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 sc.close() sc.close sc long wareruC = B / C - A / C; wareruC B / C - A / C B / C B C A / C A C if (A % C == 0L)
            wareruC++; A % C == 0L A % C A C 0L wareruC++ wareruC long wareruD = B / D - A / D; wareruD B / D - A / D B / D B D A / D A D if (A % D == 0L)
            wareruD++; A % D == 0L A % D A D 0L wareruD++ wareruD long saisyoukoubaisuu = lcm(C, D); saisyoukoubaisuu lcm(C, D) lcm C D long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu; wareruCD B / saisyoukoubaisuu - A / saisyoukoubaisuu B / saisyoukoubaisuu B saisyoukoubaisuu A / saisyoukoubaisuu A saisyoukoubaisuu if (A % saisyoukoubaisuu == 0L)
            wareruCD++; A % saisyoukoubaisuu == 0L A % saisyoukoubaisuu A saisyoukoubaisuu 0L wareruCD++ wareruCD long result = (B - A + 1L) - wareruC - wareruD + wareruCD; result (B - A + 1L) - wareruC - wareruD + wareruCD (B - A + 1L) - wareruC - wareruD (B - A + 1L) - wareruC - wareruD (B - A + 1L) B - A B A 1L wareruC wareruD wareruCD System.out.println(result) System.out.println System.out System System.out result String[] args args static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    } lcm {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(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 (long)(c/b); (long)(c/b) c b long a a long b b 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();
        sc.close();

        /** だめだったその１**/
        //        long result = LongStream.rangeClosed(A, B)
        //                .filter(i-> i%C!=0)
        //                .filter(i-> i%D!=0)
        //                .count();
        //        
        //        System.out.println(result);

        /** だめだったその２**/
        //        long resultNoHantai = LongStream.rangeClosed(A, B)
        //                .filter(i -> i % C == 0 || i % D == 0)
        //                .count();
        //
        //        long result = B - A + 1L - resultNoHantai;
        //        System.out.println(result);

        long wareruC = B / C - A / C;
        if (A % C == 0L)
            wareruC++;

        long wareruD = B / D - A / D;
        if (A % D == 0L)
            wareruD++;

        long saisyoukoubaisuu = lcm(C, D);

        long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu;
        if (A % saisyoukoubaisuu == 0L)
            wareruCD++;

        long result = (B - A + 1L) - wareruC - wareruD + wareruCD;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    }
} 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();
        sc.close();

        /** だめだったその１**/
        //        long result = LongStream.rangeClosed(A, B)
        //                .filter(i-> i%C!=0)
        //                .filter(i-> i%D!=0)
        //                .count();
        //        
        //        System.out.println(result);

        /** だめだったその２**/
        //        long resultNoHantai = LongStream.rangeClosed(A, B)
        //                .filter(i -> i % C == 0 || i % D == 0)
        //                .count();
        //
        //        long result = B - A + 1L - resultNoHantai;
        //        System.out.println(result);

        long wareruC = B / C - A / C;
        if (A % C == 0L)
            wareruC++;

        long wareruD = B / D - A / D;
        if (A % D == 0L)
            wareruD++;

        long saisyoukoubaisuu = lcm(C, D);

        long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu;
        if (A % saisyoukoubaisuu == 0L)
            wareruCD++;

        long result = (B - A + 1L) - wareruC - wareruD + wareruCD;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    }
} 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();
        sc.close();

        /** だめだったその１**/
        //        long result = LongStream.rangeClosed(A, B)
        //                .filter(i-> i%C!=0)
        //                .filter(i-> i%D!=0)
        //                .count();
        //        
        //        System.out.println(result);

        /** だめだったその２**/
        //        long resultNoHantai = LongStream.rangeClosed(A, B)
        //                .filter(i -> i % C == 0 || i % D == 0)
        //                .count();
        //
        //        long result = B - A + 1L - resultNoHantai;
        //        System.out.println(result);

        long wareruC = B / C - A / C;
        if (A % C == 0L)
            wareruC++;

        long wareruD = B / D - A / D;
        if (A % D == 0L)
            wareruD++;

        long saisyoukoubaisuu = lcm(C, D);

        long wareruCD = B / saisyoukoubaisuu - A / saisyoukoubaisuu;
        if (A % saisyoukoubaisuu == 0L)
            wareruCD++;

        long result = (B - A + 1L) - wareruC - wareruD + wareruCD;

        System.out.println(result);

    }

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