import java.util.*;

public class Main {
    public static long gcd(long a, long b) {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    }
    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }
    public static long divnum(long a, long b, long x) {
        return b / x - (a - 1) / x;
    }
    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();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    }
} import java.util.*; util.* java public class Main {
    public static long gcd(long a, long b) {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    }
    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }
    public static long divnum(long a, long b, long x) {
        return b / x - (a - 1) / x;
    }
    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();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    }
} Main public static long gcd(long a, long b) {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    } gcd {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    } while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        } a % b != 0 a % b a b 0 {
            long tmp = a % b;
            a = b;
            b = tmp;
        } long tmp = a % b; tmp a % b a b a = b a b b = tmp b tmp return b; 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 static long divnum(long a, long b, long x) {
        return b / x - (a - 1) / x;
    } divnum {
        return b / x - (a - 1) / x;
    } return b / x - (a - 1) / x; b / x - (a - 1) / x b / x b x (a - 1) / x (a - 1) a 1 x long a a long b b long x x 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();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    } 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 if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        } d % c == 0 d % c d c 0 {
            System.out.println(b - a + 1- divnum(a, b, c));
        } System.out.println(b - a + 1- divnum(a, b, c)) System.out.println System.out System System.out b - a + 1- divnum(a, b, c) b - a + 1 b - a b a 1 divnum(a, b, c) divnum a b c {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        } System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d))) System.out.println System.out System System.out b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)) b - a + 1- divnum(a, b, c) - divnum(a, b, d) b - a + 1- divnum(a, b, c) - divnum(a, b, d) b - a + 1 b - a b a 1 divnum(a, b, c) divnum a b c divnum(a, b, d) divnum a b d divnum(a, b, lcm(c, d)) divnum a b lcm(c, d) lcm c d String[] args args public class Main {
    public static long gcd(long a, long b) {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    }
    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }
    public static long divnum(long a, long b, long x) {
        return b / x - (a - 1) / x;
    }
    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();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    }
} public class Main {
    public static long gcd(long a, long b) {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    }
    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }
    public static long divnum(long a, long b, long x) {
        return b / x - (a - 1) / x;
    }
    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();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    }
} Main
import java.util.*;

public class Main {
    public static long gcd(long a, long b) {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    }
    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }
    public static long divnum(long a, long b, long x) {
        return b / x - (a - 1) / x;
    }
    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();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    }
}
