import java.util.Scanner;

/**
 * @author yoshizaki
 *131
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    }
    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.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    }
    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) {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    } main {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    } Scanner scanner= new Scanner(System.in); scanner new Scanner(System.in) long min = scanner.nextLong(); min scanner.nextLong() scanner.nextLong scanner long max = scanner.nextLong(); max scanner.nextLong() scanner.nextLong scanner long divider1 = scanner.nextLong(); divider1 scanner.nextLong() scanner.nextLong scanner long divider2 = scanner.nextLong(); divider2 scanner.nextLong() scanner.nextLong scanner long ans = 0l; ans 0l if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        } min == max && (min == divider1 || min == divider2) min == max min max (min == divider1 || min == divider2) min == divider1 min divider1 min == divider2 min divider2 {
            ans = 0;
        } ans = 0 ans 0 {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        } long min1 = min / divider1; min1 min / divider1 min divider1 if (min % divider1 == 0) min1 -=1; min % divider1 == 0 min % divider1 min divider1 0 min1 -=1 min1 1 long max1 = max / divider1; max1 max / divider1 max divider1 long min2 = min / divider2; min2 min / divider2 min divider2 if (min % divider2 == 0) min2 -=1; min % divider2 == 0 min % divider2 min divider2 0 min2 -=1 min2 1 long max2 = max / divider2; max2 max / divider2 max divider2 long crossDivider = lcm(divider1, divider2); crossDivider lcm(divider1, divider2) lcm divider1 divider2 long crossmin = min / crossDivider; crossmin min / crossDivider min crossDivider if (min % crossDivider == 0) crossmin -=1; min % crossDivider == 0 min % crossDivider min crossDivider 0 crossmin -=1 crossmin 1 long crossmax = max / crossDivider; crossmax max / crossDivider max crossDivider long mm = max1 - min1; mm max1 - min1 max1 min1 long nn = max2 - min2; nn max2 - min2 max2 min2 long cc = crossmax - crossmin; cc crossmax - crossmin crossmax crossmin ans = (max - min + 1) -(mm + nn - cc) ans (max - min + 1) -(mm + nn - cc) (max - min + 1) max - min max min 1 (mm + nn - cc) mm + nn mm nn cc System.out.println(ans) System.out.println System.out System System.out ans 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) {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    }
    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) {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    }
    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.Scanner;

/**
 * @author yoshizaki
 *131
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    }
    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);
    }
}
