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();
        
        System.out.println( f(B, C, D) - f(A - 1, C, D) );
        
    }
    
    // x以下でcまたはdで割り切れない数の個数
    public static long f(long x, long c, long d){
        return x - x / c - x / d + x / LCM(c, d);
    }
    
    public static long GCD(long a, long b){
        if ( b == 0 ) return a; 
        return GCD(b, a % b);
    }
    
    public static long LCM(long a, long b){
        return a * b / GCD(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();
        
        System.out.println( f(B, C, D) - f(A - 1, C, D) );
        
    }
    
    // x以下でcまたはdで割り切れない数の個数
    public static long f(long x, long c, long d){
        return x - x / c - x / d + x / LCM(c, d);
    }
    
    public static long GCD(long a, long b){
        if ( b == 0 ) return a; 
        return GCD(b, a % b);
    }
    
    public static long LCM(long a, long b){
        return a * b / GCD(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();
        
        System.out.println( f(B, C, D) - f(A - 1, C, D) );
        
    } main {
        
        Scanner sc = new Scanner(System.in);
        
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        System.out.println( f(B, C, D) - f(A - 1, C, D) );
        
    } 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 System.out.println( f(B, C, D) - f(A - 1, C, D) ) System.out.println System.out System System.out f(B, C, D) - f(A - 1, C, D) f(B, C, D) f B C D f(A - 1, C, D) f A - 1 A 1 C D String[] args args // x以下でcまたはdで割り切れない数の個数
    public static long f(long x, long c, long d){
        return x - x / c - x / d + x / LCM(c, d);
    } f {
        return x - x / c - x / d + x / LCM(c, d);
    } return x - x / c - x / d + x / LCM(c, d); x - x / c - x / d + x / LCM(c, d) x - x / c - x / d x - x / c - x / d x x / c x c x / d x d x / LCM(c, d) x LCM(c, d) LCM c d long x x long c c long d d 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 static long LCM(long a, long b){
        return a * b / GCD(a, b);
    } LCM {
        return a * b / GCD(a, b);
    } return a * b / GCD(a, b); a * b / GCD(a, b) a * b a b GCD(a, b) GCD 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();
        
        System.out.println( f(B, C, D) - f(A - 1, C, D) );
        
    }
    
    // x以下でcまたはdで割り切れない数の個数
    public static long f(long x, long c, long d){
        return x - x / c - x / d + x / LCM(c, d);
    }
    
    public static long GCD(long a, long b){
        if ( b == 0 ) return a; 
        return GCD(b, a % b);
    }
    
    public static long LCM(long a, long b){
        return a * b / GCD(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();
        
        System.out.println( f(B, C, D) - f(A - 1, C, D) );
        
    }
    
    // x以下でcまたはdで割り切れない数の個数
    public static long f(long x, long c, long d){
        return x - x / c - x / d + x / LCM(c, d);
    }
    
    public static long GCD(long a, long b){
        if ( b == 0 ) return a; 
        return GCD(b, a % b);
    }
    
    public static long LCM(long a, long b){
        return a * b / GCD(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();
        
        System.out.println( f(B, C, D) - f(A - 1, C, D) );
        
    }
    
    // x以下でcまたはdで割り切れない数の個数
    public static long f(long x, long c, long d){
        return x - x / c - x / d + x / LCM(c, d);
    }
    
    public static long GCD(long a, long b){
        if ( b == 0 ) return a; 
        return GCD(b, a % b);
    }
    
    public static long LCM(long a, long b){
        return a * b / GCD(a, b);
    }
}
