import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long min = sc.nextLong() - 1;
        long max = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = LCM(c, d);
        long cnt = 0;

        cnt += devide(max, c);
        cnt += devide(max, d);
        cnt -= devide(max, lcm);

        cnt -= devide(min, c);
        cnt -= devide(min, d);
        cnt += devide(min, lcm);

        System.out.println(max - min - cnt);
    }

    public static long devide(long a, long b) {
        return a / b;
    }

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

    public static long LCM(long a, long b) {
        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 min = sc.nextLong() - 1;
        long max = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = LCM(c, d);
        long cnt = 0;

        cnt += devide(max, c);
        cnt += devide(max, d);
        cnt -= devide(max, lcm);

        cnt -= devide(min, c);
        cnt -= devide(min, d);
        cnt += devide(min, lcm);

        System.out.println(max - min - cnt);
    }

    public static long devide(long a, long b) {
        return a / b;
    }

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

    public static long LCM(long a, long b) {
        return a * b / GCD(a, b);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long min = sc.nextLong() - 1;
        long max = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = LCM(c, d);
        long cnt = 0;

        cnt += devide(max, c);
        cnt += devide(max, d);
        cnt -= devide(max, lcm);

        cnt -= devide(min, c);
        cnt -= devide(min, d);
        cnt += devide(min, lcm);

        System.out.println(max - min - cnt);
    } main {
        Scanner sc = new Scanner(System.in);

        long min = sc.nextLong() - 1;
        long max = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = LCM(c, d);
        long cnt = 0;

        cnt += devide(max, c);
        cnt += devide(max, d);
        cnt -= devide(max, lcm);

        cnt -= devide(min, c);
        cnt -= devide(min, d);
        cnt += devide(min, lcm);

        System.out.println(max - min - cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long min = sc.nextLong() - 1; min sc.nextLong() - 1 sc.nextLong() sc.nextLong sc 1 long max = sc.nextLong(); max 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 lcm = LCM(c, d); lcm LCM(c, d) LCM c d long cnt = 0; cnt 0 cnt += devide(max, c) cnt devide(max, c) devide max c cnt += devide(max, d) cnt devide(max, d) devide max d cnt -= devide(max, lcm) cnt devide(max, lcm) devide max lcm cnt -= devide(min, c) cnt devide(min, c) devide min c cnt -= devide(min, d) cnt devide(min, d) devide min d cnt += devide(min, lcm) cnt devide(min, lcm) devide min lcm System.out.println(max - min - cnt) System.out.println System.out System System.out max - min - cnt max - min - cnt max min cnt String[] args args public static long devide(long a, long b) {
        return a / b;
    } devide {
        return a / b;
    } return a / b; a / b a b long a a long b b public static long GCD(long a, long b) {
        if (a < b) {
            return GCD(b, a);
        } else if (b == 0) {
            return a;
        } else {
            return GCD(b, a % b);
        }
    } GCD {
        if (a < b) {
            return GCD(b, a);
        } else if (b == 0) {
            return a;
        } else {
            return GCD(b, a % b);
        }
    } if (a < b) {
            return GCD(b, a);
        } else if (b == 0) {
            return a;
        } else {
            return GCD(b, a % b);
        } a < b a b {
            return GCD(b, a);
        } return GCD(b, a); GCD(b, a) GCD b a 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 public 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 public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long min = sc.nextLong() - 1;
        long max = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = LCM(c, d);
        long cnt = 0;

        cnt += devide(max, c);
        cnt += devide(max, d);
        cnt -= devide(max, lcm);

        cnt -= devide(min, c);
        cnt -= devide(min, d);
        cnt += devide(min, lcm);

        System.out.println(max - min - cnt);
    }

    public static long devide(long a, long b) {
        return a / b;
    }

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

    public static long LCM(long a, long b) {
        return a * b / GCD(a, b);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long min = sc.nextLong() - 1;
        long max = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = LCM(c, d);
        long cnt = 0;

        cnt += devide(max, c);
        cnt += devide(max, d);
        cnt -= devide(max, lcm);

        cnt -= devide(min, c);
        cnt -= devide(min, d);
        cnt += devide(min, lcm);

        System.out.println(max - min - cnt);
    }

    public static long devide(long a, long b) {
        return a / b;
    }

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

    public static long LCM(long a, long b) {
        return a * b / GCD(a, b);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long min = sc.nextLong() - 1;
        long max = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = LCM(c, d);
        long cnt = 0;

        cnt += devide(max, c);
        cnt += devide(max, d);
        cnt -= devide(max, lcm);

        cnt -= devide(min, c);
        cnt -= devide(min, d);
        cnt += devide(min, lcm);

        System.out.println(max - min - cnt);
    }

    public static long devide(long a, long b) {
        return a / b;
    }

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

    public static long LCM(long a, long b) {
        return a * b / GCD(a, b);
    }
}
