import java.util.*;

public class Main {
    static long INF = 1000000000000000L;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    }
    
    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 {
    static long INF = 1000000000000000L;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    }
    
    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 static long INF = 1000000000000000L; INF 1000000000000000L public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    } 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 tmp1 = b / c; tmp1 b / c b c long tmp2 = b / d; tmp2 b / d b d long tmp3 = b / lcm(c, d); tmp3 b / lcm(c, d) b lcm(c, d) lcm c d long tmp4 = (a-1) / c; tmp4 (a-1) / c (a-1) a 1 c long tmp5 = (a-1) / d; tmp5 (a-1) / d (a-1) a 1 d long tmp6 = (a-1) / lcm(c, d); tmp6 (a-1) / lcm(c, d) (a-1) a 1 lcm(c, d) lcm c d long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6)); ans (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6)) (b-a+1) b-a b a 1 ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6)) (tmp1 + tmp2 - tmp3) tmp1 + tmp2 tmp1 tmp2 tmp3 (tmp4 + tmp5 - tmp6) tmp4 + tmp5 tmp4 tmp5 tmp6 System.out.println(ans) System.out.println System.out System System.out ans 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; 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 {
    static long INF = 1000000000000000L;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    }
    
    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 {
    static long INF = 1000000000000000L;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    }
    
    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 {
    static long INF = 1000000000000000L;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    }
    
    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);
    }
}
