import 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 E = C*D;
		long F = Math.max(C,D);
		long G = Math.min(C,D);
		for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		}    
		System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) );     
	}
} import java.util.*; util.* java 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 E = C*D;
		long F = Math.max(C,D);
		long G = Math.min(C,D);
		for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		}    
		System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) );     
	}
} 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 E = C*D;
		long F = Math.max(C,D);
		long G = Math.min(C,D);
		for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		}    
		System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) );     
	} 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 = C*D;
		long F = Math.max(C,D);
		long G = Math.min(C,D);
		for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		}    
		System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) );     
	} 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 = C*D; E C*D C D long F = Math.max(C,D); F Math.max(C,D) Math.max Math C D long G = Math.min(C,D); G Math.min(C,D) Math.min Math C D for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		} long i=1; long i=1; i 1 i*i<=G i*i i i G i++ i++ i {
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		} {
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		} if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			} G%i==0 G%i G i 0 {
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			} if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				} F%(G/i)==0 F%(G/i) F (G/i) G i 0 {
					E = (C*D)/(G/i);
					break;
				} E = (C*D)/(G/i) E (C*D)/(G/i) (C*D) C D (G/i) G i break; if( F%i==0 ){
					E = (C*D)/i;
				} F%i==0 F%i F i 0 {
					E = (C*D)/i;
				} E = (C*D)/i E (C*D)/i (C*D) C D i System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) ) System.out.println System.out System System.out (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) (B-A+1) - (B/C+B/D-B/E) (B-A+1) B-A B A 1 (B/C+B/D-B/E) B/C+B/D B/C B C B/D B D B/E B E ((A-1)/C+(A-1)/D-(A-1)/E) (A-1)/C+(A-1)/D (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/E (A-1) A 1 E String[] args args 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 E = C*D;
		long F = Math.max(C,D);
		long G = Math.min(C,D);
		for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		}    
		System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) );     
	}
} 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 E = C*D;
		long F = Math.max(C,D);
		long G = Math.min(C,D);
		for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		}    
		System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) );     
	}
} Main
import 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 E = C*D;
		long F = Math.max(C,D);
		long G = Math.min(C,D);
		for( long i=1; i*i<=G; i++ ){
			if( G%i==0 ){
				if( F%(G/i)==0 ){
					E = (C*D)/(G/i);
					break;
				}
				if( F%i==0 ){
					E = (C*D)/i;
				}
			}
		}    
		System.out.println( (B-A+1) - (B/C+B/D-B/E) + ((A-1)/C+(A-1)/D-(A-1)/E) );     
	}
}
