import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 *
 * @author dkcs
 */
class Main
{
    static class FastReader {
        
        BufferedReader br;
        StringTokenizer st;
        
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    static class Node {
        
        long pp;
        long a, b;
        
        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }
    
    static class Comp implements Comparator<Node> {
        
        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) 
    {
        FastReader sc = new FastReader();
        String s[]=sc.nextLine().split(" ");
        BigInteger a=new BigInteger(s[0]);
        BigInteger b=new BigInteger(s[1]);
        BigInteger c=new BigInteger(s[2]);
        BigInteger d=new BigInteger(s[3]);
        BigInteger g=c.gcd(d);
        BigInteger lcm=(c.multiply(d)).divide(g);
        
        BigInteger ca=(a.subtract(BigInteger.ONE)).divide(c);
        BigInteger cb=b.divide(c);
        
        BigInteger da=(a.subtract(BigInteger.ONE)).divide(d);
        BigInteger db=b.divide(d);
        
        BigInteger la=(a.subtract(BigInteger.ONE)).divide(lcm);
        BigInteger lb=b.divide(lcm);
        
        BigInteger ans1=(cb.subtract(ca));
        BigInteger ans2=(db.subtract(da));
        BigInteger ans3=(lb.subtract(la));
        
        BigInteger ans=ans1.add(ans2);
        ans=ans.subtract(ans3);
        
        BigInteger t=b.subtract(a.subtract(BigInteger.ONE));
        ans=t.subtract(ans);
        System.out.println(ans);


        
        
        
        
        
    }
    
    
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.math.BigInteger; BigInteger java.math import java.util.Comparator; Comparator java.util import java.util.StringTokenizer; StringTokenizer java.util class Main
{
    static class FastReader {
        
        BufferedReader br;
        StringTokenizer st;
        
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    static class Node {
        
        long pp;
        long a, b;
        
        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }
    
    static class Comp implements Comparator<Node> {
        
        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) 
    {
        FastReader sc = new FastReader();
        String s[]=sc.nextLine().split(" ");
        BigInteger a=new BigInteger(s[0]);
        BigInteger b=new BigInteger(s[1]);
        BigInteger c=new BigInteger(s[2]);
        BigInteger d=new BigInteger(s[3]);
        BigInteger g=c.gcd(d);
        BigInteger lcm=(c.multiply(d)).divide(g);
        
        BigInteger ca=(a.subtract(BigInteger.ONE)).divide(c);
        BigInteger cb=b.divide(c);
        
        BigInteger da=(a.subtract(BigInteger.ONE)).divide(d);
        BigInteger db=b.divide(d);
        
        BigInteger la=(a.subtract(BigInteger.ONE)).divide(lcm);
        BigInteger lb=b.divide(lcm);
        
        BigInteger ans1=(cb.subtract(ca));
        BigInteger ans2=(db.subtract(da));
        BigInteger ans3=(lb.subtract(la));
        
        BigInteger ans=ans1.add(ans2);
        ans=ans.subtract(ans3);
        
        BigInteger t=b.subtract(a.subtract(BigInteger.ONE));
        ans=t.subtract(ans);
        System.out.println(ans);


        
        
        
        
        
    }
    
    
} Main public static void main(String[] args) 
    {
        FastReader sc = new FastReader();
        String s[]=sc.nextLine().split(" ");
        BigInteger a=new BigInteger(s[0]);
        BigInteger b=new BigInteger(s[1]);
        BigInteger c=new BigInteger(s[2]);
        BigInteger d=new BigInteger(s[3]);
        BigInteger g=c.gcd(d);
        BigInteger lcm=(c.multiply(d)).divide(g);
        
        BigInteger ca=(a.subtract(BigInteger.ONE)).divide(c);
        BigInteger cb=b.divide(c);
        
        BigInteger da=(a.subtract(BigInteger.ONE)).divide(d);
        BigInteger db=b.divide(d);
        
        BigInteger la=(a.subtract(BigInteger.ONE)).divide(lcm);
        BigInteger lb=b.divide(lcm);
        
        BigInteger ans1=(cb.subtract(ca));
        BigInteger ans2=(db.subtract(da));
        BigInteger ans3=(lb.subtract(la));
        
        BigInteger ans=ans1.add(ans2);
        ans=ans.subtract(ans3);
        
        BigInteger t=b.subtract(a.subtract(BigInteger.ONE));
        ans=t.subtract(ans);
        System.out.println(ans);


        
        
        
        
        
    } main {
        FastReader sc = new FastReader();
        String s[]=sc.nextLine().split(" ");
        BigInteger a=new BigInteger(s[0]);
        BigInteger b=new BigInteger(s[1]);
        BigInteger c=new BigInteger(s[2]);
        BigInteger d=new BigInteger(s[3]);
        BigInteger g=c.gcd(d);
        BigInteger lcm=(c.multiply(d)).divide(g);
        
        BigInteger ca=(a.subtract(BigInteger.ONE)).divide(c);
        BigInteger cb=b.divide(c);
        
        BigInteger da=(a.subtract(BigInteger.ONE)).divide(d);
        BigInteger db=b.divide(d);
        
        BigInteger la=(a.subtract(BigInteger.ONE)).divide(lcm);
        BigInteger lb=b.divide(lcm);
        
        BigInteger ans1=(cb.subtract(ca));
        BigInteger ans2=(db.subtract(da));
        BigInteger ans3=(lb.subtract(la));
        
        BigInteger ans=ans1.add(ans2);
        ans=ans.subtract(ans3);
        
        BigInteger t=b.subtract(a.subtract(BigInteger.ONE));
        ans=t.subtract(ans);
        System.out.println(ans);


        
        
        
        
        
    } FastReader sc = new FastReader(); sc new FastReader() String s[]=sc.nextLine().split(" "); s sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " BigInteger a=new BigInteger(s[0]); a new BigInteger(s[0]) BigInteger b=new BigInteger(s[1]); b new BigInteger(s[1]) BigInteger c=new BigInteger(s[2]); c new BigInteger(s[2]) BigInteger d=new BigInteger(s[3]); d new BigInteger(s[3]) BigInteger g=c.gcd(d); g c.gcd(d) c.gcd c d BigInteger lcm=(c.multiply(d)).divide(g); lcm (c.multiply(d)).divide(g) (c.multiply(d)).divide (c.multiply(d)) c.multiply c d g BigInteger ca=(a.subtract(BigInteger.ONE)).divide(c); ca (a.subtract(BigInteger.ONE)).divide(c) (a.subtract(BigInteger.ONE)).divide (a.subtract(BigInteger.ONE)) a.subtract a BigInteger.ONE BigInteger BigInteger.ONE c BigInteger cb=b.divide(c); cb b.divide(c) b.divide b c BigInteger da=(a.subtract(BigInteger.ONE)).divide(d); da (a.subtract(BigInteger.ONE)).divide(d) (a.subtract(BigInteger.ONE)).divide (a.subtract(BigInteger.ONE)) a.subtract a BigInteger.ONE BigInteger BigInteger.ONE d BigInteger db=b.divide(d); db b.divide(d) b.divide b d BigInteger la=(a.subtract(BigInteger.ONE)).divide(lcm); la (a.subtract(BigInteger.ONE)).divide(lcm) (a.subtract(BigInteger.ONE)).divide (a.subtract(BigInteger.ONE)) a.subtract a BigInteger.ONE BigInteger BigInteger.ONE lcm BigInteger lb=b.divide(lcm); lb b.divide(lcm) b.divide b lcm BigInteger ans1=(cb.subtract(ca)); ans1 (cb.subtract(ca)) cb.subtract cb ca BigInteger ans2=(db.subtract(da)); ans2 (db.subtract(da)) db.subtract db da BigInteger ans3=(lb.subtract(la)); ans3 (lb.subtract(la)) lb.subtract lb la BigInteger ans=ans1.add(ans2); ans ans1.add(ans2) ans1.add ans1 ans2 ans=ans.subtract(ans3) ans ans.subtract(ans3) ans.subtract ans ans3 BigInteger t=b.subtract(a.subtract(BigInteger.ONE)); t b.subtract(a.subtract(BigInteger.ONE)) b.subtract b a.subtract(BigInteger.ONE) a.subtract a BigInteger.ONE BigInteger BigInteger.ONE ans=t.subtract(ans) ans t.subtract(ans) t.subtract t ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args static class FastReader {
        
        BufferedReader br;
        StringTokenizer st;
        
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        } FastReader {
            br = new BufferedReader(new InputStreamReader(System.in));
        } br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } next {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    st = new StringTokenizer(br.readLine());
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next double nextDouble() {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        } nextLine {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        } String str = ""; str "" try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } IOException e {
                e.printStackTrace();
            } e.printStackTrace() e.printStackTrace e {
                str = br.readLine();
            } str = br.readLine() str br.readLine() br.readLine br return str; str static class Node {
        
        long pp;
        long a, b;
        
        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    } Node long pp; pp long a a b; b Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        } Node {
            a = x;
            b = y;
            pp = a * b;
        } a = x a x b = y b y pp = a * b pp a * b a b long x x long y y static class Comp implements Comparator<Node> {
        
        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    } Comp public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        } compare {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        } if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            } o1.pp > o2.pp o1.pp o1 o1.pp o2.pp o2 o2.pp {
                return 1;
            } return 1; 1 {
                return -1;
            } return -1; -1 1 Node o1 o1 Node o2 o2 Comparator
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 *
 * @author dkcs
 */
class Main
{
    static class FastReader {
        
        BufferedReader br;
        StringTokenizer st;
        
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    static class Node {
        
        long pp;
        long a, b;
        
        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }
    
    static class Comp implements Comparator<Node> {
        
        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) 
    {
        FastReader sc = new FastReader();
        String s[]=sc.nextLine().split(" ");
        BigInteger a=new BigInteger(s[0]);
        BigInteger b=new BigInteger(s[1]);
        BigInteger c=new BigInteger(s[2]);
        BigInteger d=new BigInteger(s[3]);
        BigInteger g=c.gcd(d);
        BigInteger lcm=(c.multiply(d)).divide(g);
        
        BigInteger ca=(a.subtract(BigInteger.ONE)).divide(c);
        BigInteger cb=b.divide(c);
        
        BigInteger da=(a.subtract(BigInteger.ONE)).divide(d);
        BigInteger db=b.divide(d);
        
        BigInteger la=(a.subtract(BigInteger.ONE)).divide(lcm);
        BigInteger lb=b.divide(lcm);
        
        BigInteger ans1=(cb.subtract(ca));
        BigInteger ans2=(db.subtract(da));
        BigInteger ans3=(lb.subtract(la));
        
        BigInteger ans=ans1.add(ans2);
        ans=ans.subtract(ans3);
        
        BigInteger t=b.subtract(a.subtract(BigInteger.ONE));
        ans=t.subtract(ans);
        System.out.println(ans);


        
        
        
        
        
    }
    
    
}
