import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0, l = 0, as = 0, bs = 0;

        if (c > d) {
            long f = c;
            c = d;
            d = f;
        }

        l = lcm(c, d);
        as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l));
        bs = b - ((b / c) + (b / d) - (b / l));
        ans = bs - as;
        System.out.println(ans);
        sc.close();
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0, l = 0, as = 0, bs = 0;

        if (c > d) {
            long f = c;
            c = d;
            d = f;
        }

        l = lcm(c, d);
        as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l));
        bs = b - ((b / c) + (b / d) - (b / l));
        ans = bs - as;
        System.out.println(ans);
        sc.close();
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} Main public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0, l = 0, as = 0, bs = 0;

        if (c > d) {
            long f = c;
            c = d;
            d = f;
        }

        l = lcm(c, d);
        as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l));
        bs = b - ((b / c) + (b / d) - (b / l));
        ans = bs - as;
        System.out.println(ans);
        sc.close();
    } main {
        
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0, l = 0, as = 0, bs = 0;

        if (c > d) {
            long f = c;
            c = d;
            d = f;
        }

        l = lcm(c, d);
        as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l));
        bs = b - ((b / c) + (b / d) - (b / l));
        ans = bs - as;
        System.out.println(ans);
        sc.close();
    } 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 ans = 0 ans 0 l = 0 l 0 as = 0 as 0 bs = 0; bs 0 if (c > d) {
            long f = c;
            c = d;
            d = f;
        } c > d c d {
            long f = c;
            c = d;
            d = f;
        } long f = c; f c c = d c d d = f d f l = lcm(c, d) l lcm(c, d) lcm c d as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l)) as (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l)) (a - 1) a 1 (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l)) ((a - 1) / c) + ((a - 1) / d) ((a - 1) / c) (a - 1) a 1 c ((a - 1) / d) (a - 1) a 1 d ((a - 1) / l) (a - 1) a 1 l bs = b - ((b / c) + (b / d) - (b / l)) bs b - ((b / c) + (b / d) - (b / l)) b ((b / c) + (b / d) - (b / l)) (b / c) + (b / d) (b / c) b c (b / d) b d (b / l) b l ans = bs - as ans bs - as bs as System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public 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 / gcd(m, n)) n gcd(m, n) gcd m n long m m long n n public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    } gcd {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    } if (b == 0) {
            return a;
        } b == 0 b 0 {
            return a;
        } return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0, l = 0, as = 0, bs = 0;

        if (c > d) {
            long f = c;
            c = d;
            d = f;
        }

        l = lcm(c, d);
        as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l));
        bs = b - ((b / c) + (b / d) - (b / l));
        ans = bs - as;
        System.out.println(ans);
        sc.close();
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0, l = 0, as = 0, bs = 0;

        if (c > d) {
            long f = c;
            c = d;
            d = f;
        }

        l = lcm(c, d);
        as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l));
        bs = b - ((b / c) + (b / d) - (b / l));
        ans = bs - as;
        System.out.println(ans);
        sc.close();
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0, l = 0, as = 0, bs = 0;

        if (c > d) {
            long f = c;
            c = d;
            d = f;
        }

        l = lcm(c, d);
        as = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l));
        bs = b - ((b / c) + (b / d) - (b / l));
        ans = bs - as;
        System.out.println(ans);
        sc.close();
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}
