import java.util.*;

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 count = B/C - A/C;
        if (A % C == 0) {
            count++;
        }
        count += B/D - A/D;
        long lcm = lcm(C, D);
        count -= (B / lcm) - (A / lcm);

        System.out.println(B - A + 1 - count);
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}
 import java.util.*; util.* java 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 count = B/C - A/C;
        if (A % C == 0) {
            count++;
        }
        count += B/D - A/D;
        long lcm = lcm(C, D);
        count -= (B / lcm) - (A / lcm);

        System.out.println(B - A + 1 - count);
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }
        if (b == 0) {
            return a;
        }
        return gcd(b, 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 count = B/C - A/C;
        if (A % C == 0) {
            count++;
        }
        count += B/D - A/D;
        long lcm = lcm(C, D);
        count -= (B / lcm) - (A / lcm);

        System.out.println(B - A + 1 - count);
    } main {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long count = B/C - A/C;
        if (A % C == 0) {
            count++;
        }
        count += B/D - A/D;
        long lcm = lcm(C, D);
        count -= (B / lcm) - (A / lcm);

        System.out.println(B - A + 1 - count);
    } 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 count = B/C - A/C; count B/C - A/C B/C B C A/C A C if (A % C == 0) {
            count++;
        } A % C == 0 A % C A C 0 {
            count++;
        } count++ count count += B/D - A/D count B/D - A/D B/D B D A/D A D long lcm = lcm(C, D); lcm lcm(C, D) lcm C D count -= (B / lcm) - (A / lcm) count (B / lcm) - (A / lcm) (B / lcm) B lcm (A / lcm) A lcm System.out.println(B - A + 1 - count) System.out.println System.out System System.out B - A + 1 - count B - A + 1 B - A B A 1 count String[] args args private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    } lcm {
        return a * b / gcd(a, b);
    } 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 private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    } gcd {
        if (a < b) {
            return gcd(b, a);
        }
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    } if (a < b) {
            return gcd(b, a);
        } a < b a b {
            return gcd(b, a);
        } return gcd(b, a); gcd(b, a) gcd b a if (b == 0) {
            return a;
        } b == 0 b 0 {
            return a;
        } return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b
import java.util.*;

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 count = B/C - A/C;
        if (A % C == 0) {
            count++;
        }
        count += B/D - A/D;
        long lcm = lcm(C, D);
        count -= (B / lcm) - (A / lcm);

        System.out.println(B - A + 1 - count);
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

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

