import java.util.*;
/**
 * Main
 */
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 l = lcm(C,D);
        long val1 = B - (B/C + B/D) + B/l;
        long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l;
        System.out.println(val1-val2);
        sc.close();
    }

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

    static long lcm(long a, long b) {
        if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a*b/gcd(a,b);
    }
} import java.util.*; util.* java 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 l = lcm(C,D);
        long val1 = B - (B/C + B/D) + B/l;
        long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l;
        System.out.println(val1-val2);
        sc.close();
    }

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

    static long lcm(long a, long b) {
        if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a*b/gcd(a,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();

        long l = lcm(C,D);
        long val1 = B - (B/C + B/D) + B/l;
        long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l;
        System.out.println(val1-val2);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long l = lcm(C,D);
        long val1 = B - (B/C + B/D) + B/l;
        long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l;
        System.out.println(val1-val2);
        sc.close();
    } 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 l = lcm(C,D); l lcm(C,D) lcm C D long val1 = B - (B/C + B/D) + B/l; val1 B - (B/C + B/D) + B/l B - (B/C + B/D) B (B/C + B/D) B/C B C B/D B D B/l B l long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l; val2 (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l (A-1) - ((A-1)/C + (A-1)/D) (A-1) A 1 ((A-1)/C + (A-1)/D) (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/l (A-1) A 1 l System.out.println(val1-val2) System.out.println System.out System System.out val1-val2 val1 val2 sc.close() sc.close sc String[] args args //b < a
    static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b+a;
        else return gcd(b,a%b);
    } gcd {
        if (a == 0 || b == 0) return b+a;
        else return gcd(b,a%b);
    } if (a == 0 || b == 0) return b+a;
        else return gcd(b,a%b); a == 0 || b == 0 a == 0 a 0 b == 0 b 0 return b+a; b+a b a return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b static long lcm(long a, long b) {
        if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a*b/gcd(a,b);
    } lcm {
        if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a*b/gcd(a,b);
    } if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        } a <= b a b {
            long tmp = a;
            a = b;
            b = tmp;
        } long tmp = a; tmp a a = b a b b = tmp b tmp return a*b/gcd(a,b); a*b/gcd(a,b) a*b a b gcd(a,b) gcd a 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();

        long l = lcm(C,D);
        long val1 = B - (B/C + B/D) + B/l;
        long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l;
        System.out.println(val1-val2);
        sc.close();
    }

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

    static long lcm(long a, long b) {
        if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a*b/gcd(a,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();

        long l = lcm(C,D);
        long val1 = B - (B/C + B/D) + B/l;
        long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l;
        System.out.println(val1-val2);
        sc.close();
    }

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

    static long lcm(long a, long b) {
        if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a*b/gcd(a,b);
    }
} Main
import java.util.*;
/**
 * Main
 */
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 l = lcm(C,D);
        long val1 = B - (B/C + B/D) + B/l;
        long val2 = (A-1) - ((A-1)/C + (A-1)/D) + (A-1)/l;
        System.out.println(val1-val2);
        sc.close();
    }

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

    static long lcm(long a, long b) {
        if(a <= b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a*b/gcd(a,b);
    }
}