import java.util.Scanner;

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(C,D);
	    
	    long count = 0;
	 
	    	long a_max = B/C;
	    	long a_min = A/C;
	    	long a_c=0;
	    	
	    	if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	}
	    		
	    	
	    	long b_max = B/D;
	    	long b_min = A/D;
	    	long b_c=0;
	    	
	    	if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	}
	    	
	    	long c_max = B/CD;
	    	long c_min = A/CD;
	    	long c_c=0;
	    	
	    	if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	}
	    	
	    	count = a_c+b_c-c_c;
	    	
	    
	    System.out.println(B-A-count+1);
	}
	static public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	}
	public static long LCM(long a, long b) { 
		return (a * b) / GCF(a, b); 
		}

	
} 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(C,D);
	    
	    long count = 0;
	 
	    	long a_max = B/C;
	    	long a_min = A/C;
	    	long a_c=0;
	    	
	    	if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	}
	    		
	    	
	    	long b_max = B/D;
	    	long b_min = A/D;
	    	long b_c=0;
	    	
	    	if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	}
	    	
	    	long c_max = B/CD;
	    	long c_min = A/CD;
	    	long c_c=0;
	    	
	    	if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	}
	    	
	    	count = a_c+b_c-c_c;
	    	
	    
	    System.out.println(B-A-count+1);
	}
	static public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	}
	public static long LCM(long a, long b) { 
		return (a * b) / GCF(a, b); 
		}

	
} 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(C,D);
	    
	    long count = 0;
	 
	    	long a_max = B/C;
	    	long a_min = A/C;
	    	long a_c=0;
	    	
	    	if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	}
	    		
	    	
	    	long b_max = B/D;
	    	long b_min = A/D;
	    	long b_c=0;
	    	
	    	if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	}
	    	
	    	long c_max = B/CD;
	    	long c_min = A/CD;
	    	long c_c=0;
	    	
	    	if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	}
	    	
	    	count = a_c+b_c-c_c;
	    	
	    
	    System.out.println(B-A-count+1);
	} 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(C,D);
	    
	    long count = 0;
	 
	    	long a_max = B/C;
	    	long a_min = A/C;
	    	long a_c=0;
	    	
	    	if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	}
	    		
	    	
	    	long b_max = B/D;
	    	long b_min = A/D;
	    	long b_c=0;
	    	
	    	if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	}
	    	
	    	long c_max = B/CD;
	    	long c_min = A/CD;
	    	long c_c=0;
	    	
	    	if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	}
	    	
	    	count = a_c+b_c-c_c;
	    	
	    
	    System.out.println(B-A-count+1);
	} 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(C,D); CD LCM(C,D) LCM C D long count = 0; count 0 long a_max = B/C; a_max B/C B C long a_min = A/C; a_min A/C A C long a_c=0; a_c 0 if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	} a_min==0 a_min 0 {
	    		a_c=a_max;
	    	} a_c=a_max a_c a_max if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	} A%C==0 A%C A C 0 {
	    		a_c=a_max-a_min+1;
	    	} a_c=a_max-a_min+1 a_c a_max-a_min+1 a_max-a_min a_max a_min 1 {
	    		a_c=a_max-a_min;
	    	} a_c=a_max-a_min a_c a_max-a_min a_max a_min long b_max = B/D; b_max B/D B D long b_min = A/D; b_min A/D A D long b_c=0; b_c 0 if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	} b_min==0 b_min 0 {
	    		b_c=b_max;
	    	} b_c=b_max b_c b_max if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	} A%D==0 A%D A D 0 {
	    		b_c=b_max-b_min+1;
	    	} b_c=b_max-b_min+1 b_c b_max-b_min+1 b_max-b_min b_max b_min 1 {
	    		b_c=b_max-b_min;
	    	} b_c=b_max-b_min b_c b_max-b_min b_max b_min long c_max = B/CD; c_max B/CD B CD long c_min = A/CD; c_min A/CD A CD long c_c=0; c_c 0 if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	} c_min==0 c_min 0 {
	    		c_c=c_max;
	    	} c_c=c_max c_c c_max if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	} A%CD==0 A%CD A CD 0 {
	    		c_c=c_max-c_min+1;
	    	} c_c=c_max-c_min+1 c_c c_max-c_min+1 c_max-c_min c_max c_min 1 {
	    		c_c=c_max-c_min;
	    	} c_c=c_max-c_min c_c c_max-c_min c_max c_min count = a_c+b_c-c_c count a_c+b_c-c_c a_c+b_c a_c b_c c_c System.out.println(B-A-count+1) System.out.println System.out System System.out B-A-count+1 B-A-count B-A-count B A count 1 String[] args args static public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	} GCF {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	} if (b == 0) return a;
	    else return (GCF (b, a % b)); b == 0 b 0 return a; a return (GCF (b, a % b)); (GCF (b, a % b)) GCF b a % b a b long a a long b b public static long LCM(long a, long b) { 
		return (a * b) / GCF(a, b); 
		} LCM { 
		return (a * b) / GCF(a, b); 
		} return (a * b) / GCF(a, b); (a * b) / GCF(a, b) (a * b) a b GCF(a, b) GCF a b 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(C,D);
	    
	    long count = 0;
	 
	    	long a_max = B/C;
	    	long a_min = A/C;
	    	long a_c=0;
	    	
	    	if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	}
	    		
	    	
	    	long b_max = B/D;
	    	long b_min = A/D;
	    	long b_c=0;
	    	
	    	if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	}
	    	
	    	long c_max = B/CD;
	    	long c_min = A/CD;
	    	long c_c=0;
	    	
	    	if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	}
	    	
	    	count = a_c+b_c-c_c;
	    	
	    
	    System.out.println(B-A-count+1);
	}
	static public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	}
	public static long LCM(long a, long b) { 
		return (a * b) / GCF(a, 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(C,D);
	    
	    long count = 0;
	 
	    	long a_max = B/C;
	    	long a_min = A/C;
	    	long a_c=0;
	    	
	    	if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	}
	    		
	    	
	    	long b_max = B/D;
	    	long b_min = A/D;
	    	long b_c=0;
	    	
	    	if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	}
	    	
	    	long c_max = B/CD;
	    	long c_min = A/CD;
	    	long c_c=0;
	    	
	    	if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	}
	    	
	    	count = a_c+b_c-c_c;
	    	
	    
	    System.out.println(B-A-count+1);
	}
	static public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	}
	public static long LCM(long a, long b) { 
		return (a * b) / GCF(a, b); 
		}

	
} Main
import java.util.Scanner;

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(C,D);
	    
	    long count = 0;
	 
	    	long a_max = B/C;
	    	long a_min = A/C;
	    	long a_c=0;
	    	
	    	if (a_min==0) {
	    		a_c=a_max;
	    	}
	    	
	    	
	    	else if (A%C==0) {
	    		a_c=a_max-a_min+1;
	    	}
	    	
	    	else {
	    		a_c=a_max-a_min;
	    	}
	    		
	    	
	    	long b_max = B/D;
	    	long b_min = A/D;
	    	long b_c=0;
	    	
	    	if (b_min==0) {
	    		b_c=b_max;
	    	}
	    	
	    	
	    	else if (A%D==0) {
	    		b_c=b_max-b_min+1;
	    	}
	    	
	    	else {
	    		b_c=b_max-b_min;
	    	}
	    	
	    	long c_max = B/CD;
	    	long c_min = A/CD;
	    	long c_c=0;
	    	
	    	if (c_min==0) {
	    		c_c=c_max;
	    	}
	    	
	    	
	    	else if (A%CD==0) {
	    		c_c=c_max-c_min+1;
	    	}
	    	
	    	else {
	    		c_c=c_max-c_min;
	    	}
	    	
	    	count = a_c+b_c-c_c;
	    	
	    
	    System.out.println(B-A-count+1);
	}
	static public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	}
	public static long LCM(long a, long b) { 
		return (a * b) / GCF(a, b); 
		}

	
}