import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

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

        long cntCup = b/c;
        long cntCdown = (a-1)/c;
        long cntC = cntCup - cntCdown;

        long cntDup = b/d;
        long cntDdown = (a-1)/d;
        long cntD = cntDup - cntDdown;

        long e = lcm(c,d);
        long cntEup = b/e;
        long cntEdown = (a-1)/e;
        long cntE = cntEup - cntEdown;

        long cnt = b - a + 1 - cntC - cntD + cntE;
        System.out.println(cnt);

    }

    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);
    }

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

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

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

        long cntCup = b/c;
        long cntCdown = (a-1)/c;
        long cntC = cntCup - cntCdown;

        long cntDup = b/d;
        long cntDdown = (a-1)/d;
        long cntD = cntDup - cntDdown;

        long e = lcm(c,d);
        long cntEup = b/e;
        long cntEdown = (a-1)/e;
        long cntE = cntEup - cntEdown;

        long cnt = b - a + 1 - cntC - cntD + cntE;
        System.out.println(cnt);

    }

    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);
    }

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

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
} Main public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    } main {
        Main main = new Main();
        main.solve(args);
    } Main main = new Main(); main new Main() main.solve(args) main.solve main args String[] args args public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

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

        long cntCup = b/c;
        long cntCdown = (a-1)/c;
        long cntC = cntCup - cntCdown;

        long cntDup = b/d;
        long cntDdown = (a-1)/d;
        long cntD = cntDup - cntDdown;

        long e = lcm(c,d);
        long cntEup = b/e;
        long cntEdown = (a-1)/e;
        long cntE = cntEup - cntEdown;

        long cnt = b - a + 1 - cntC - cntD + cntE;
        System.out.println(cnt);

    } solve {
        MyScanner scanner = new MyScanner();

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

        long cntCup = b/c;
        long cntCdown = (a-1)/c;
        long cntC = cntCup - cntCdown;

        long cntDup = b/d;
        long cntDdown = (a-1)/d;
        long cntD = cntDup - cntDdown;

        long e = lcm(c,d);
        long cntEup = b/e;
        long cntEdown = (a-1)/e;
        long cntE = cntEup - cntEdown;

        long cnt = b - a + 1 - cntC - cntD + cntE;
        System.out.println(cnt);

    } MyScanner scanner = new MyScanner(); scanner new MyScanner() long a = scanner.nextLong(); a scanner.nextLong() scanner.nextLong scanner long b = scanner.nextLong(); b scanner.nextLong() scanner.nextLong scanner long c = scanner.nextLong(); c scanner.nextLong() scanner.nextLong scanner long d = scanner.nextLong(); d scanner.nextLong() scanner.nextLong scanner long cntCup = b/c; cntCup b/c b c long cntCdown = (a-1)/c; cntCdown (a-1)/c (a-1) a 1 c long cntC = cntCup - cntCdown; cntC cntCup - cntCdown cntCup cntCdown long cntDup = b/d; cntDup b/d b d long cntDdown = (a-1)/d; cntDdown (a-1)/d (a-1) a 1 d long cntD = cntDup - cntDdown; cntD cntDup - cntDdown cntDup cntDdown long e = lcm(c,d); e lcm(c,d) lcm c d long cntEup = b/e; cntEup b/e b e long cntEdown = (a-1)/e; cntEdown (a-1)/e (a-1) a 1 e long cntE = cntEup - cntEdown; cntE cntEup - cntEdown cntEup cntEdown long cnt = b - a + 1 - cntC - cntD + cntE; cnt b - a + 1 - cntC - cntD + cntE b - a + 1 - cntC - cntD b - a + 1 - cntC - cntD b - a + 1 b - a b a 1 cntC cntD cntE System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args 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 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 class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    } MyScanner String[] s; s int i; i BufferedReader br; br String reg = " "; reg " " MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        } MyScanner {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        } s = new String[0] s new String[0] 0 i = 0 i 0 br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        } next {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        } try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } if (i < s.length) return s[i++]; i < s.length i s.length s s.length return s[i++]; s[i++] s i++ i String line = br.readLine(); line br.readLine() br.readLine br while (line.equals("")) {line = br.readLine();} line.equals("") line.equals line "" {line = br.readLine();} line = br.readLine() line br.readLine() br.readLine br s = line.split(reg, 0) s line.split(reg, 0) line.split line reg 0 i = 0 i 0 return s[i++]; s[i++] s i++ i return null; null public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        } nextInt {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        } try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next return -1; -1 1 public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        } nextDouble {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        } try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {return Double.parseDouble(next());} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next return -1; -1 1 public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        } nextLong {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        } try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next return -1; -1 1 public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

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

        long cntCup = b/c;
        long cntCdown = (a-1)/c;
        long cntC = cntCup - cntCdown;

        long cntDup = b/d;
        long cntDdown = (a-1)/d;
        long cntD = cntDup - cntDdown;

        long e = lcm(c,d);
        long cntEup = b/e;
        long cntEdown = (a-1)/e;
        long cntE = cntEup - cntEdown;

        long cnt = b - a + 1 - cntC - cntD + cntE;
        System.out.println(cnt);

    }

    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);
    }

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

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

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

        long cntCup = b/c;
        long cntCdown = (a-1)/c;
        long cntC = cntCup - cntCdown;

        long cntDup = b/d;
        long cntDdown = (a-1)/d;
        long cntD = cntDup - cntDdown;

        long e = lcm(c,d);
        long cntEup = b/e;
        long cntEdown = (a-1)/e;
        long cntE = cntEup - cntEdown;

        long cnt = b - a + 1 - cntC - cntD + cntE;
        System.out.println(cnt);

    }

    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);
    }

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

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

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

        long cntCup = b/c;
        long cntCdown = (a-1)/c;
        long cntC = cntCup - cntCdown;

        long cntDup = b/d;
        long cntDdown = (a-1)/d;
        long cntD = cntDup - cntDdown;

        long e = lcm(c,d);
        long cntEup = b/e;
        long cntEdown = (a-1)/e;
        long cntE = cntEup - cntEdown;

        long cnt = b - a + 1 - cntC - cntD + cntE;
        System.out.println(cnt);

    }

    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);
    }

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

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}