import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    }

    //最小公倍数lcm・コピペ
    static long lcm (long a, long b) {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    }

} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    }

    //最小公倍数lcm・コピペ
    static long lcm (long a, long b) {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    } 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 a = 0; a 0 long m = 0 m 0 n = 0 n 0 mn = 0; mn 0 m = B/C-(A-1)/C m B/C-(A-1)/C B/C B C (A-1)/C (A-1) A 1 C n = B/D-(A-1)/D n B/D-(A-1)/D B/D B D (A-1)/D (A-1) A 1 D mn = B/lcm(C,D)-(A-1)/lcm(C,D) mn B/lcm(C,D)-(A-1)/lcm(C,D) B/lcm(C,D) B lcm(C,D) lcm C D (A-1)/lcm(C,D) (A-1) A 1 lcm(C,D) lcm C D a = (B-A+1)-(m+n-mn) a (B-A+1)-(m+n-mn) (B-A+1) B-A B A 1 (m+n-mn) m+n m n mn System.out.println(a) System.out.println System.out System System.out a String[] args args //最小公倍数lcm・コピペ
    static long lcm (long a, long b) {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    } lcm {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    } long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    } (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
		    a = b;
		    b = temp;
	    } a = b a b b = temp b temp return (c/b); (c/b) c b long a a long b b public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    }

    //最小公倍数lcm・コピペ
    static long lcm (long a, long b) {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    }

} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    }

    //最小公倍数lcm・コピペ
    static long lcm (long a, long b) {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    }

} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    }

    //最小公倍数lcm・コピペ
    static long lcm (long a, long b) {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    }

}