import 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();
        long lcm = lcm(c,d);
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long al = (a-1)/lcm;
        long bl = b/lcm;
        System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al)));
        sc.close();

    }

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

    public 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 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 lcm = lcm(c,d);
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long al = (a-1)/lcm;
        long bl = b/lcm;
        System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al)));
        sc.close();

    }

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

    public 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 lcm = lcm(c,d);
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long al = (a-1)/lcm;
        long bl = b/lcm;
        System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al)));
        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 lcm = lcm(c,d);
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long al = (a-1)/lcm;
        long bl = b/lcm;
        System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al)));
        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 lcm = lcm(c,d); lcm lcm(c,d) lcm c d long ac = (a-1)/c; ac (a-1)/c (a-1) a 1 c long bc = b/c; bc b/c b c long ad = (a-1)/d; ad (a-1)/d (a-1) a 1 d long bd = b/d; bd b/d b d long al = (a-1)/lcm; al (a-1)/lcm (a-1) a 1 lcm long bl = b/lcm; bl b/lcm b lcm System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al))) System.out.println System.out System System.out b - (a-1) - (bc + bd - bl - (ac + ad - al)) b - (a-1) - (bc + bd - bl - (ac + ad - al)) b (a-1) a 1 (bc + bd - bl - (ac + ad - al)) bc + bd - bl - (ac + ad - al) bc + bd bc bd bl (ac + ad - al) ac + ad ac ad al sc.close() sc.close sc String[] args args 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 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); gcd(b, a) gcd b a if (b == 0)
            return a; b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b 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 lcm = lcm(c,d);
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long al = (a-1)/lcm;
        long bl = b/lcm;
        System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al)));
        sc.close();

    }

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

    public static long gcd(long a, long b) {
        if (a < b)
            return gcd(b, a);
        if (b == 0)
            return a;
        return gcd(b, 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 lcm = lcm(c,d);
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long al = (a-1)/lcm;
        long bl = b/lcm;
        System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al)));
        sc.close();

    }

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

    public 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
import 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();
        long lcm = lcm(c,d);
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long al = (a-1)/lcm;
        long bl = b/lcm;
        System.out.println(b - (a-1) - (bc + bd - bl - (ac + ad - al)));
        sc.close();

    }

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

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

}
