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-a+1)/c;
        if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;}
        long f = (b-a+1)/d;
        if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;}
        long g = (b-a+1)/lcm(c,d);
        if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;}
		System.out.println(b-a+1-e-f+g);
	}
} 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-a+1)/c;
        if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;}
        long f = (b-a+1)/d;
        if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;}
        long g = (b-a+1)/lcm(c,d);
        if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;}
		System.out.println(b-a+1-e-f+g);
	}
} 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-a+1)/c;
        if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;}
        long f = (b-a+1)/d;
        if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;}
        long g = (b-a+1)/lcm(c,d);
        if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;}
		System.out.println(b-a+1-e-f+g);
	} 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-a+1)/c;
        if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;}
        long f = (b-a+1)/d;
        if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;}
        long g = (b-a+1)/lcm(c,d);
        if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;}
		System.out.println(b-a+1-e-f+g);
	} 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-a+1)/c; e (b-a+1)/c (b-a+1) b-a b a 1 c if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;} a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0) a%c+(b-a+1)%c-1>=c a%c+(b-a+1)%c-1 a%c+(b-a+1)%c a%c a c (b-a+1)%c (b-a+1) b-a b a 1 c 1 c (a%c==0 &&(b-a+1)%c!=0) a%c==0 a%c a c 0 (b-a+1)%c!=0 (b-a+1)%c (b-a+1) b-a b a 1 c 0 {e++;} e++ e long f = (b-a+1)/d; f (b-a+1)/d (b-a+1) b-a b a 1 d if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;} a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0) a%d+(b-a+1)%d-1>=d a%d+(b-a+1)%d-1 a%d+(b-a+1)%d a%d a d (b-a+1)%d (b-a+1) b-a b a 1 d 1 d (a%d==0 &&(b-a+1)%d!=0) a%d==0 a%d a d 0 (b-a+1)%d!=0 (b-a+1)%d (b-a+1) b-a b a 1 d 0 {f++;} f++ f long g = (b-a+1)/lcm(c,d); g (b-a+1)/lcm(c,d) (b-a+1) b-a b a 1 lcm(c,d) lcm c d if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;} a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0) a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d) a%lcm(c,d)+(b-a+1)%lcm(c,d)-1 a%lcm(c,d)+(b-a+1)%lcm(c,d) a%lcm(c,d) a lcm(c,d) lcm c d (b-a+1)%lcm(c,d) (b-a+1) b-a b a 1 lcm(c,d) lcm c d 1 lcm(c,d) lcm c d (a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0) a%lcm(c,d)==0 a%lcm(c,d) a lcm(c,d) lcm c d 0 (b-a+1)%lcm(c,d)!=0 (b-a+1)%lcm(c,d) (b-a+1) b-a b a 1 lcm(c,d) lcm c d 0 {g++;} g++ g System.out.println(b-a+1-e-f+g) System.out.println System.out System System.out b-a+1-e-f+g b-a+1-e-f b-a+1-e-f b-a+1 b-a b a 1 e f g 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-a+1)/c;
        if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;}
        long f = (b-a+1)/d;
        if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;}
        long g = (b-a+1)/lcm(c,d);
        if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;}
		System.out.println(b-a+1-e-f+g);
	}
} 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-a+1)/c;
        if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;}
        long f = (b-a+1)/d;
        if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;}
        long g = (b-a+1)/lcm(c,d);
        if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;}
		System.out.println(b-a+1-e-f+g);
	}
} 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-a+1)/c;
        if(a%c+(b-a+1)%c-1>=c||(a%c==0 &&(b-a+1)%c!=0)){e++;}
        long f = (b-a+1)/d;
        if(a%d+(b-a+1)%d-1>=d||(a%d==0 &&(b-a+1)%d!=0)){f++;}
        long g = (b-a+1)/lcm(c,d);
        if(a%lcm(c,d)+(b-a+1)%lcm(c,d)-1>=lcm(c,d)||(a%lcm(c,d)==0 &&(b-a+1)%lcm(c,d)!=0)){g++;}
		System.out.println(b-a+1-e-f+g);
	}
}
