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

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long D = Long.parseLong(s[3]);
        System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)));
    }
    
    public static long divider(long A, long B,long div) {
        long start = 0;
        long end = 0;
        if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        }
        
        if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        }
        if(start > end)return 0;
        return (end - start) / div + 1;
    }
    
    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.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long D = Long.parseLong(s[3]);
        System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)));
    }
    
    public static long divider(long A, long B,long div) {
        long start = 0;
        long end = 0;
        if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        }
        
        if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        }
        if(start > end)return 0;
        return (end - start) / div + 1;
    }
    
    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[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long D = Long.parseLong(s[3]);
        System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)));
    } main {
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long D = Long.parseLong(s[3]);
        System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)));
    } BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in)); stdR new BufferedReader(new InputStreamReader(System.in)) String[] s = stdR.readLine().split(" "); s stdR.readLine().split(" ") stdR.readLine().split stdR.readLine() stdR.readLine stdR " " long A = Long.parseLong(s[0]); A Long.parseLong(s[0]) Long.parseLong Long s[0] s 0 long B = Long.parseLong(s[1]); B Long.parseLong(s[1]) Long.parseLong Long s[1] s 1 long C = Long.parseLong(s[2]); C Long.parseLong(s[2]) Long.parseLong Long s[2] s 2 long D = Long.parseLong(s[3]); D Long.parseLong(s[3]) Long.parseLong Long s[3] s 3 System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D))) System.out.println System.out System System.out (B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)) (B - A + 1) - divider(A, B, C) - divider(A, B, D) (B - A + 1) - divider(A, B, C) - divider(A, B, D) (B - A + 1) B - A B A 1 divider(A, B, C) divider A B C divider(A, B, D) divider A B D divider(A, B, lcm(C,D)) divider A B lcm(C,D) lcm C D String args[] args public static long divider(long A, long B,long div) {
        long start = 0;
        long end = 0;
        if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        }
        
        if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        }
        if(start > end)return 0;
        return (end - start) / div + 1;
    } divider {
        long start = 0;
        long end = 0;
        if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        }
        
        if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        }
        if(start > end)return 0;
        return (end - start) / div + 1;
    } long start = 0; start 0 long end = 0; end 0 if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        } A <= div A div {
            start = div;
        } start = div start div {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        } if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            } A % div == 0 A % div A div 0 {
                start = A;
            } start = A start A {
                start = A + div - A % div;
            } start = A + div - A % div start A + div - A % div A + div A div A % div A div if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        } B < div B div {
          return 0;
        } return 0; 0 {
            end = B - B % div;
        } end = B - B % div end B - B % div B B % div B div if(start > end)return 0; start > end start end return 0; 0 return (end - start) / div + 1; (end - start) / div + 1 (end - start) / div (end - start) end start div 1 long A A long B B long div div 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[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long D = Long.parseLong(s[3]);
        System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)));
    }
    
    public static long divider(long A, long B,long div) {
        long start = 0;
        long end = 0;
        if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        }
        
        if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        }
        if(start > end)return 0;
        return (end - start) / div + 1;
    }
    
    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[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long D = Long.parseLong(s[3]);
        System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)));
    }
    
    public static long divider(long A, long B,long div) {
        long start = 0;
        long end = 0;
        if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        }
        
        if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        }
        if(start > end)return 0;
        return (end - start) / div + 1;
    }
    
    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.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long D = Long.parseLong(s[3]);
        System.out.println((B - A + 1) - divider(A, B, C) - divider(A, B, D) + divider(A, B, lcm(C,D)));
    }
    
    public static long divider(long A, long B,long div) {
        long start = 0;
        long end = 0;
        if(A <= div) {
            start = div;
        }else {
            if(A % div == 0) {
                start = A;
            }else {
                start = A + div - A % div;
            }
        }
        
        if(B < div) {
          return 0;
        }else {
            end = B - B % div;
        }
        if(start > end)return 0;
        return (end - start) / div + 1;
    }
    
    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);
    }
}
