import java.util.Arrays;
import java.util.Scanner;

/**
 * ABC111C
 */
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 CD = lcm(Math.max(C, D),Math.min(C, D));
        
        long cnum = num(C,A,B);
        long dnum = num(D,A,B);;
        long cdnum = num(CD,A,B);
       
        long ans = (B-A+1)-(cnum+dnum-cdnum);
        
//        System.out.println(cnum +" "+ dnum + " " + cdnum);
        

        System.out.println(ans);
        
        sc.close();
    }
    
    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (long)(c/b);
    }
    
    static long num(long n,long A,long B) {
    	if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util 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 CD = lcm(Math.max(C, D),Math.min(C, D));
        
        long cnum = num(C,A,B);
        long dnum = num(D,A,B);;
        long cdnum = num(CD,A,B);
       
        long ans = (B-A+1)-(cnum+dnum-cdnum);
        
//        System.out.println(cnum +" "+ dnum + " " + cdnum);
        

        System.out.println(ans);
        
        sc.close();
    }
    
    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (long)(c/b);
    }
    
    static long num(long n,long A,long B) {
    	if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        }
    }
} 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 CD = lcm(Math.max(C, D),Math.min(C, D));
        
        long cnum = num(C,A,B);
        long dnum = num(D,A,B);;
        long cdnum = num(CD,A,B);
       
        long ans = (B-A+1)-(cnum+dnum-cdnum);
        
//        System.out.println(cnum +" "+ dnum + " " + cdnum);
        

        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 CD = lcm(Math.max(C, D),Math.min(C, D));
        
        long cnum = num(C,A,B);
        long dnum = num(D,A,B);;
        long cdnum = num(CD,A,B);
       
        long ans = (B-A+1)-(cnum+dnum-cdnum);
        
//        System.out.println(cnum +" "+ dnum + " " + cdnum);
        

        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 CD = lcm(Math.max(C, D),Math.min(C, D)); CD lcm(Math.max(C, D),Math.min(C, D)) lcm Math.max(C, D) Math.max Math C D Math.min(C, D) Math.min Math C D long cnum = num(C,A,B); cnum num(C,A,B) num C A B long dnum = num(D,A,B); dnum num(D,A,B) num D A B long cdnum = num(CD,A,B); cdnum num(CD,A,B) num CD A B long ans = (B-A+1)-(cnum+dnum-cdnum); ans (B-A+1)-(cnum+dnum-cdnum) (B-A+1) B-A B A 1 (cnum+dnum-cdnum) cnum+dnum cnum dnum cdnum System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (long)(c/b);
    } lcm {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (long)(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 (long)(c/b); (long)(c/b) c b long a a long b b static long num(long n,long A,long B) {
    	if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        }
    } num {
    	if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        }
    } if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        } A%n==0 A%n A n 0 {
        	return (B-(A))/n+1;
        } return (B-(A))/n+1; (B-(A))/n+1 (B-(A))/n (B-(A)) B (A) n 1 if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        } (A+(n-A%n)>B) A+(n-A%n) A (n-A%n) n A%n A n B {
        	return 0;
        } return 0; 0 {
        	return(B-(A+(n-A%n)))/n+1;
        } return(B-(A+(n-A%n)))/n+1; (B-(A+(n-A%n)))/n+1 (B-(A+(n-A%n)))/n (B-(A+(n-A%n))) B (A+(n-A%n)) A (n-A%n) n A%n A n n 1 long n n 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 CD = lcm(Math.max(C, D),Math.min(C, D));
        
        long cnum = num(C,A,B);
        long dnum = num(D,A,B);;
        long cdnum = num(CD,A,B);
       
        long ans = (B-A+1)-(cnum+dnum-cdnum);
        
//        System.out.println(cnum +" "+ dnum + " " + cdnum);
        

        System.out.println(ans);
        
        sc.close();
    }
    
    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (long)(c/b);
    }
    
    static long num(long n,long A,long B) {
    	if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        }
    }
} 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 CD = lcm(Math.max(C, D),Math.min(C, D));
        
        long cnum = num(C,A,B);
        long dnum = num(D,A,B);;
        long cdnum = num(CD,A,B);
       
        long ans = (B-A+1)-(cnum+dnum-cdnum);
        
//        System.out.println(cnum +" "+ dnum + " " + cdnum);
        

        System.out.println(ans);
        
        sc.close();
    }
    
    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (long)(c/b);
    }
    
    static long num(long n,long A,long B) {
    	if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

/**
 * ABC111C
 */
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 CD = lcm(Math.max(C, D),Math.min(C, D));
        
        long cnum = num(C,A,B);
        long dnum = num(D,A,B);;
        long cdnum = num(CD,A,B);
       
        long ans = (B-A+1)-(cnum+dnum-cdnum);
        
//        System.out.println(cnum +" "+ dnum + " " + cdnum);
        

        System.out.println(ans);
        
        sc.close();
    }
    
    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (long)(c/b);
    }
    
    static long num(long n,long A,long B) {
    	if(A%n==0) {
        	return (B-(A))/n+1;
        }else if((A+(n-A%n)>B)){
        	return 0;
        }else {
        	return(B-(A+(n-A%n)))/n+1;
        }
    }
}