import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	long a = scan.nextLong() - 1;
      	long b = scan.nextLong();
      	long c = scan.nextLong();
      	long d = scan.nextLong();
      	long g = gcd(c,d);
      	long l = c * d / g;
      	long countb, counta;
      	countb = b - b/c - b/d + b/l;
      	counta = a - a/c - a/d + a/l;
        
      	System.out.print(countb - counta);
    }
  	public static long gcd(long m , long n){
      if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      }
    }
 
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	long a = scan.nextLong() - 1;
      	long b = scan.nextLong();
      	long c = scan.nextLong();
      	long d = scan.nextLong();
      	long g = gcd(c,d);
      	long l = c * d / g;
      	long countb, counta;
      	countb = b - b/c - b/d + b/l;
      	counta = a - a/c - a/d + a/l;
        
      	System.out.print(countb - counta);
    }
  	public static long gcd(long m , long n){
      if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      }
    }
 
} Main public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	long a = scan.nextLong() - 1;
      	long b = scan.nextLong();
      	long c = scan.nextLong();
      	long d = scan.nextLong();
      	long g = gcd(c,d);
      	long l = c * d / g;
      	long countb, counta;
      	countb = b - b/c - b/d + b/l;
      	counta = a - a/c - a/d + a/l;
        
      	System.out.print(countb - counta);
    } main {
    	Scanner scan = new Scanner(System.in);
      	long a = scan.nextLong() - 1;
      	long b = scan.nextLong();
      	long c = scan.nextLong();
      	long d = scan.nextLong();
      	long g = gcd(c,d);
      	long l = c * d / g;
      	long countb, counta;
      	countb = b - b/c - b/d + b/l;
      	counta = a - a/c - a/d + a/l;
        
      	System.out.print(countb - counta);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a = scan.nextLong() - 1; a scan.nextLong() - 1 scan.nextLong() scan.nextLong scan 1 long b = scan.nextLong(); b scan.nextLong() scan.nextLong scan long c = scan.nextLong(); c scan.nextLong() scan.nextLong scan long d = scan.nextLong(); d scan.nextLong() scan.nextLong scan long g = gcd(c,d); g gcd(c,d) gcd c d long l = c * d / g; l c * d / g c * d c d g long countb countb counta; counta countb = b - b/c - b/d + b/l countb b - b/c - b/d + b/l b - b/c - b/d b - b/c - b/d b b/c b c b/d b d b/l b l counta = a - a/c - a/d + a/l counta a - a/c - a/d + a/l a - a/c - a/d a - a/c - a/d a a/c a c a/d a d a/l a l System.out.print(countb - counta) System.out.print System.out System System.out countb - counta countb counta String[] args args public static long gcd(long m , long n){
      if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      }
    } gcd {
      if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      }
    } if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      } n == 0 n 0 {
      	return m;
      } return m; m {
        	return gcd(n, m%n);
      } return gcd(n, m%n); gcd(n, m%n) gcd n m%n m n long m m long n n public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	long a = scan.nextLong() - 1;
      	long b = scan.nextLong();
      	long c = scan.nextLong();
      	long d = scan.nextLong();
      	long g = gcd(c,d);
      	long l = c * d / g;
      	long countb, counta;
      	countb = b - b/c - b/d + b/l;
      	counta = a - a/c - a/d + a/l;
        
      	System.out.print(countb - counta);
    }
  	public static long gcd(long m , long n){
      if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      }
    }
 
} public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	long a = scan.nextLong() - 1;
      	long b = scan.nextLong();
      	long c = scan.nextLong();
      	long d = scan.nextLong();
      	long g = gcd(c,d);
      	long l = c * d / g;
      	long countb, counta;
      	countb = b - b/c - b/d + b/l;
      	counta = a - a/c - a/d + a/l;
        
      	System.out.print(countb - counta);
    }
  	public static long gcd(long m , long n){
      if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      }
    }
 
} Main
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	long a = scan.nextLong() - 1;
      	long b = scan.nextLong();
      	long c = scan.nextLong();
      	long d = scan.nextLong();
      	long g = gcd(c,d);
      	long l = c * d / g;
      	long countb, counta;
      	countb = b - b/c - b/d + b/l;
      	counta = a - a/c - a/d + a/l;
        
      	System.out.print(countb - counta);
    }
  	public static long gcd(long m , long n){
      if(n == 0){
      	return m;
      }
      else{
        	return gcd(n, m%n);
      }
    }
 
}