import java.util.*;
public class Main {
	 public static long gcd(long x,long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
    public static long lcm(long x,long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    }
    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 e = b/c;
        long f = b/d;        
        long g = b/lcm(c,d);
        long h = (a-1)/c;
        long i = (a-1)/d;        
        long j = (a-1)/lcm(c,d);
		System.out.println(b-e-f+g-a+1+h+i-j);
	}
} import java.util.*; util.* java public class Main {
	 public static long gcd(long x,long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
    public static long lcm(long x,long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    }
    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 e = b/c;
        long f = b/d;        
        long g = b/lcm(c,d);
        long h = (a-1)/c;
        long i = (a-1)/d;        
        long j = (a-1)/lcm(c,d);
		System.out.println(b-e-f+g-a+1+h+i-j);
	}
} Main public static long gcd(long x,long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    } gcd {
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    } if(x < y) return gcd(y, x); x < y x y return gcd(y, x); gcd(y, x) gcd y x if(y == 0) return x; y == 0 y 0 return x; x return gcd(y, x % y); gcd(y, x % y) gcd y x % y x y long x x long y y public static long lcm(long x,long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    } lcm {                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    } return x*y/gcd(x,y); x*y/gcd(x,y) x*y x y gcd(x,y) gcd x y long x x long y y 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 e = b/c;
        long f = b/d;        
        long g = b/lcm(c,d);
        long h = (a-1)/c;
        long i = (a-1)/d;        
        long j = (a-1)/lcm(c,d);
		System.out.println(b-e-f+g-a+1+h+i-j);
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long e = b/c;
        long f = b/d;        
        long g = b/lcm(c,d);
        long h = (a-1)/c;
        long i = (a-1)/d;        
        long j = (a-1)/lcm(c,d);
		System.out.println(b-e-f+g-a+1+h+i-j);
	} 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 e = b/c; e b/c b c long f = b/d; f b/d b d long g = b/lcm(c,d); g b/lcm(c,d) b lcm(c,d) lcm c d long h = (a-1)/c; h (a-1)/c (a-1) a 1 c long i = (a-1)/d; i (a-1)/d (a-1) a 1 d long j = (a-1)/lcm(c,d); j (a-1)/lcm(c,d) (a-1) a 1 lcm(c,d) lcm c d System.out.println(b-e-f+g-a+1+h+i-j) System.out.println System.out System System.out b-e-f+g-a+1+h+i-j b-e-f+g-a+1+h+i h b-e-f+g-a+1+h+i b-e-f+g-a b-e-f+g b-e-f b-e-f b e f g a 1 h i j String[] args args public class Main {
	 public static long gcd(long x,long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
    public static long lcm(long x,long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    }
    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 e = b/c;
        long f = b/d;        
        long g = b/lcm(c,d);
        long h = (a-1)/c;
        long i = (a-1)/d;        
        long j = (a-1)/lcm(c,d);
		System.out.println(b-e-f+g-a+1+h+i-j);
	}
} public class Main {
	 public static long gcd(long x,long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
    public static long lcm(long x,long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    }
    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 e = b/c;
        long f = b/d;        
        long g = b/lcm(c,d);
        long h = (a-1)/c;
        long i = (a-1)/d;        
        long j = (a-1)/lcm(c,d);
		System.out.println(b-e-f+g-a+1+h+i-j);
	}
} Main
import java.util.*;
public class Main {
	 public static long gcd(long x,long y){
        if(x < y) return gcd(y, x);
        if(y == 0) return x;
        return gcd(y, x % y);
    }
    public static long lcm(long x,long y){                                                              
        return x*y/gcd(x,y);                                                                                                                                                                                                                
    }
    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 e = b/c;
        long f = b/d;        
        long g = b/lcm(c,d);
        long h = (a-1)/c;
        long i = (a-1)/d;        
        long j = (a-1)/lcm(c,d);
		System.out.println(b-e-f+g-a+1+h+i-j);
	}
}
