import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long C = Long.parseLong(sc.next());
        long D = Long.parseLong(sc.next());
        long bcac;
        long bdac;
        long bacd;
        if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        }
        if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        }
        if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        }
        long count = bcac + bdac - bacd;
        System.out.println(B-A-count+1);

    }
    
    public static long max(long x, long y) {
        if(x <= y) {
            return y;
        }else {
            return x;
        }
    }
    
    public static long saiyaku(long x, long y) {
        long w = 0;
        if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        }
        w = y;
        y = x % y;
        x = w;
        if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        }
    }
    
    
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long C = Long.parseLong(sc.next());
        long D = Long.parseLong(sc.next());
        long bcac;
        long bdac;
        long bacd;
        if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        }
        if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        }
        if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        }
        long count = bcac + bdac - bacd;
        System.out.println(B-A-count+1);

    }
    
    public static long max(long x, long y) {
        if(x <= y) {
            return y;
        }else {
            return x;
        }
    }
    
    public static long saiyaku(long x, long y) {
        long w = 0;
        if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        }
        w = y;
        y = x % y;
        x = w;
        if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        }
    }
    
    
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long C = Long.parseLong(sc.next());
        long D = Long.parseLong(sc.next());
        long bcac;
        long bdac;
        long bacd;
        if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        }
        if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        }
        if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        }
        long count = bcac + bdac - bacd;
        System.out.println(B-A-count+1);

    } main {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long C = Long.parseLong(sc.next());
        long D = Long.parseLong(sc.next());
        long bcac;
        long bdac;
        long bacd;
        if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        }
        if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        }
        if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        }
        long count = bcac + bdac - bacd;
        System.out.println(B-A-count+1);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = Long.parseLong(sc.next()); A Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long B = Long.parseLong(sc.next()); B Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long C = Long.parseLong(sc.next()); C Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long D = Long.parseLong(sc.next()); D Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long bcac; bcac long bdac; bdac long bacd; bacd if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        } A % C == 0 A % C A C 0 {
            bcac = B/C - A/C + 1;
        } bcac = B/C - A/C + 1 bcac B/C - A/C + 1 B/C - A/C B/C B C A/C A C 1 {
            bcac = B/C - A/C;
        } bcac = B/C - A/C bcac B/C - A/C B/C B C A/C A C if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        } A % D == 0 A % D A D 0 {
            bdac = B/D - A/D + 1;
        } bdac = B/D - A/D + 1 bdac B/D - A/D + 1 B/D - A/D B/D B D A/D A D 1 {
            bdac = B/D - A/D;
        } bdac = B/D - A/D bdac B/D - A/D B/D B D A/D A D if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        } A % (C*D/saiyaku(C,D)) == 0 A % (C*D/saiyaku(C,D)) A (C*D/saiyaku(C,D)) C*D C D saiyaku(C,D) saiyaku C D 0 {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        } bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1 bacd B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1 B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) B/(C*D/saiyaku(C,D)) B (C*D/saiyaku(C,D)) C*D C D saiyaku(C,D) saiyaku C D A/(C*D/saiyaku(C,D)) A (C*D/saiyaku(C,D)) C*D C D saiyaku(C,D) saiyaku C D 1 {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        } bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) bacd B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) B/(C*D/saiyaku(C,D)) B (C*D/saiyaku(C,D)) C*D C D saiyaku(C,D) saiyaku C D A/(C*D/saiyaku(C,D)) A (C*D/saiyaku(C,D)) C*D C D saiyaku(C,D) saiyaku C D long count = bcac + bdac - bacd; count bcac + bdac - bacd bcac + bdac bcac bdac bacd System.out.println(B-A-count+1) System.out.println System.out System System.out B-A-count+1 B-A-count B-A-count B A count 1 String[] args args public static long max(long x, long y) {
        if(x <= y) {
            return y;
        }else {
            return x;
        }
    } max {
        if(x <= y) {
            return y;
        }else {
            return x;
        }
    } if(x <= y) {
            return y;
        }else {
            return x;
        } x <= y x y {
            return y;
        } return y; y {
            return x;
        } return x; x long x x long y y public static long saiyaku(long x, long y) {
        long w = 0;
        if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        }
        w = y;
        y = x % y;
        x = w;
        if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        }
    } saiyaku {
        long w = 0;
        if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        }
        w = y;
        y = x % y;
        x = w;
        if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        }
    } long w = 0; w 0 if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        } x < y x y {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        } w = x w x x = y x y y = w y w return saiyaku(x, y); saiyaku(x, y) saiyaku x y w = y w y y = x % y y x % y x y x = w x w if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        } y == 0 y 0 {
            return x;
        } return x; x {
            
            return saiyaku(x, y);
        } return saiyaku(x, y); saiyaku(x, y) saiyaku x y long x x long y y public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long C = Long.parseLong(sc.next());
        long D = Long.parseLong(sc.next());
        long bcac;
        long bdac;
        long bacd;
        if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        }
        if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        }
        if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        }
        long count = bcac + bdac - bacd;
        System.out.println(B-A-count+1);

    }
    
    public static long max(long x, long y) {
        if(x <= y) {
            return y;
        }else {
            return x;
        }
    }
    
    public static long saiyaku(long x, long y) {
        long w = 0;
        if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        }
        w = y;
        y = x % y;
        x = w;
        if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        }
    }
    
    
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long C = Long.parseLong(sc.next());
        long D = Long.parseLong(sc.next());
        long bcac;
        long bdac;
        long bacd;
        if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        }
        if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        }
        if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        }
        long count = bcac + bdac - bacd;
        System.out.println(B-A-count+1);

    }
    
    public static long max(long x, long y) {
        if(x <= y) {
            return y;
        }else {
            return x;
        }
    }
    
    public static long saiyaku(long x, long y) {
        long w = 0;
        if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        }
        w = y;
        y = x % y;
        x = w;
        if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        }
    }
    
    
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long C = Long.parseLong(sc.next());
        long D = Long.parseLong(sc.next());
        long bcac;
        long bdac;
        long bacd;
        if(A % C == 0) {
            bcac = B/C - A/C + 1;
        }else {
            bcac = B/C - A/C;
        }
        if(A % D == 0) {
            bdac = B/D - A/D + 1;
        }else {
            bdac = B/D - A/D;
        }
        if(A % (C*D/saiyaku(C,D)) == 0) {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D)) + 1;
        }else {
            bacd = B/(C*D/saiyaku(C,D)) - A/(C*D/saiyaku(C,D));
        }
        long count = bcac + bdac - bacd;
        System.out.println(B-A-count+1);

    }
    
    public static long max(long x, long y) {
        if(x <= y) {
            return y;
        }else {
            return x;
        }
    }
    
    public static long saiyaku(long x, long y) {
        long w = 0;
        if(x < y) {
            w = x;
            x = y;
            y = w;
            return saiyaku(x, y);
        }
        w = y;
        y = x % y;
        x = w;
        if(y == 0) {
            return x;
        }else {
            
            return saiyaku(x, y);
        }
    }
    
    
}