import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} Main public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    } main {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    } 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 range = b - a + 1; range b - a + 1 b - a b a 1 long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c); cMultiple Math.floorDiv(b, c) - Math.floorDiv(a - 1, c) Math.floorDiv(b, c) Math.floorDiv Math b c Math.floorDiv(a - 1, c) Math.floorDiv Math a - 1 a 1 c long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d); dMultiple Math.floorDiv(b, d) - Math.floorDiv(a - 1, d) Math.floorDiv(b, d) Math.floorDiv Math b d Math.floorDiv(a - 1, d) Math.floorDiv Math a - 1 a 1 d long chohuku = lcm(c , d); chohuku lcm(c , d) lcm c d long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku); cdMultiple Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku) Math.floorDiv(b, chohuku) Math.floorDiv Math b chohuku Math.floorDiv(a - 1, chohuku) Math.floorDiv Math a - 1 a 1 chohuku System.out.println(range - (cMultiple + dMultiple - cdMultiple)) System.out.println System.out System System.out range - (cMultiple + dMultiple - cdMultiple) range (cMultiple + dMultiple - cdMultiple) cMultiple + dMultiple cMultiple dMultiple cdMultiple String[] args args private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    } lcm {
        return m * n / gcd(m, n);
    } return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } gcd {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

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