import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long[] nums=new long[4];
  	for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	}
  	long e,g=0;
  	long n1=nums[2],n2=nums[3];
  	
  	while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	}
  			
  	long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)));
  	System.out.print(f);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long[] nums=new long[4];
  	for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	}
  	long e,g=0;
  	long n1=nums[2],n2=nums[3];
  	
  	while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	}
  			
  	long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)));
  	System.out.print(f);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long[] nums=new long[4];
  	for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	}
  	long e,g=0;
  	long n1=nums[2],n2=nums[3];
  	
  	while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	}
  			
  	long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)));
  	System.out.print(f);
  } main {
    Scanner sc = new Scanner(System.in);
  	long[] nums=new long[4];
  	for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	}
  	long e,g=0;
  	long n1=nums[2],n2=nums[3];
  	
  	while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	}
  			
  	long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)));
  	System.out.print(f);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long[] nums=new long[4]; nums new long[4] 4 for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	} int i=0; int i=0; i 0 i<4 i 4 i++ i++ i {
  		nums[i]=sc.nextLong();
  	} {
  		nums[i]=sc.nextLong();
  	} nums[i]=sc.nextLong() nums[i] nums i sc.nextLong() sc.nextLong sc long e e g=0; g 0 long n1=nums[2] n1 nums[2] nums 2 n2=nums[3]; n2 nums[3] nums 3 while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	} g==0 g 0 {
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	} if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		} n2%n1==0 n2%n1 n2 n1 0 {
  			g=n1;
  		} g=n1 g n1 {
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		} e=n1%n2 e n1%n2 n1 n2 n1=n2 n1 n2 n2=e n2 e long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g))); f (nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g))) (nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g))) nums[1] nums 1 (nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)) nums[1]/nums[2]+nums[1]/nums[3] nums[1]/nums[2] nums[1] nums 1 nums[2] nums 2 nums[1]/nums[3] nums[1] nums 1 nums[3] nums 3 nums[1]/(nums[2]*nums[3]/g) nums[1] nums 1 (nums[2]*nums[3]/g) nums[2]*nums[3] nums[2] nums 2 nums[3] nums 3 g (nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g))) nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)) nums[0] nums 0 1 ((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)) (nums[0]-1)/nums[2]+(nums[0]-1)/nums[3] (nums[0]-1)/nums[2] (nums[0]-1) nums[0] nums 0 1 nums[2] nums 2 (nums[0]-1)/nums[3] (nums[0]-1) nums[0] nums 0 1 nums[3] nums 3 (nums[0]-1)/(nums[2]*nums[3]/g) (nums[0]-1) nums[0] nums 0 1 (nums[2]*nums[3]/g) nums[2]*nums[3] nums[2] nums 2 nums[3] nums 3 g System.out.print(f) System.out.print System.out System System.out f String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long[] nums=new long[4];
  	for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	}
  	long e,g=0;
  	long n1=nums[2],n2=nums[3];
  	
  	while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	}
  			
  	long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)));
  	System.out.print(f);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long[] nums=new long[4];
  	for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	}
  	long e,g=0;
  	long n1=nums[2],n2=nums[3];
  	
  	while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	}
  			
  	long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)));
  	System.out.print(f);
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long[] nums=new long[4];
  	for(int i=0;i<4;i++){
  		nums[i]=sc.nextLong();
  	}
  	long e,g=0;
  	long n1=nums[2],n2=nums[3];
  	
  	while(g==0){
  		if(n2%n1==0){
  			g=n1;
  		}else{
  			e=n1%n2;
  			n1=n2;
  			n2=e;
  		}
  	}
  			
  	long f=(nums[1]-(nums[1]/nums[2]+nums[1]/nums[3]-nums[1]/(nums[2]*nums[3]/g)))-(nums[0]-1-((nums[0]-1)/nums[2]+(nums[0]-1)/nums[3]-(nums[0]-1)/(nums[2]*nums[3]/g)));
  	System.out.print(f);
  }
}