import java.util.*;

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 ans_sum=B-A+1;
		long ans_div_c=B/C-A/C;
		long ans_div_d=B/D-A/D;
		long cd=C*D/gcd(C,D);
		long ans_div_cd=B/cd-A/cd;
		if (A%C==0) {
			ans_div_c+=1;
		}
		if (A%D==0) {
			ans_div_d+=1;
		}
		if (A%cd==0) {
			ans_div_cd+=1;
		}
		System.out.println(ans_sum-ans_div_c-ans_div_d+ans_div_cd);
	}

	static long gcd(long a,long b) {
	    long temp;
	    while ((temp=a%b)!=0) {
	        a=b;
	        b=temp;
	    }
	    return b;
	}
} import java.util.*; util.* java 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 ans_sum=B-A+1;
		long ans_div_c=B/C-A/C;
		long ans_div_d=B/D-A/D;
		long cd=C*D/gcd(C,D);
		long ans_div_cd=B/cd-A/cd;
		if (A%C==0) {
			ans_div_c+=1;
		}
		if (A%D==0) {
			ans_div_d+=1;
		}
		if (A%cd==0) {
			ans_div_cd+=1;
		}
		System.out.println(ans_sum-ans_div_c-ans_div_d+ans_div_cd);
	}

	static long gcd(long a,long b) {
	    long temp;
	    while ((temp=a%b)!=0) {
	        a=b;
	        b=temp;
	    }
	    return 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 ans_sum=B-A+1;
		long ans_div_c=B/C-A/C;
		long ans_div_d=B/D-A/D;
		long cd=C*D/gcd(C,D);
		long ans_div_cd=B/cd-A/cd;
		if (A%C==0) {
			ans_div_c+=1;
		}
		if (A%D==0) {
			ans_div_d+=1;
		}
		if (A%cd==0) {
			ans_div_cd+=1;
		}
		System.out.println(ans_sum-ans_div_c-ans_div_d+ans_div_cd);
	} main {
		Scanner sc = new Scanner(System.in);
		long A=sc.nextLong();
		long B=sc.nextLong();
		long C=sc.nextLong();
		long D=sc.nextLong();

		long ans_sum=B-A+1;
		long ans_div_c=B/C-A/C;
		long ans_div_d=B/D-A/D;
		long cd=C*D/gcd(C,D);
		long ans_div_cd=B/cd-A/cd;
		if (A%C==0) {
			ans_div_c+=1;
		}
		if (A%D==0) {
			ans_div_d+=1;
		}
		if (A%cd==0) {
			ans_div_cd+=1;
		}
		System.out.println(ans_sum-ans_div_c-ans_div_d+ans_div_cd);
	} 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 ans_sum=B-A+1; ans_sum B-A+1 B-A B A 1 long ans_div_c=B/C-A/C; ans_div_c B/C-A/C B/C B C A/C A C long ans_div_d=B/D-A/D; ans_div_d B/D-A/D B/D B D A/D A D long cd=C*D/gcd(C,D); cd C*D/gcd(C,D) C*D C D gcd(C,D) gcd C D long ans_div_cd=B/cd-A/cd; ans_div_cd B/cd-A/cd B/cd B cd A/cd A cd if (A%C==0) {
			ans_div_c+=1;
		} A%C==0 A%C A C 0 {
			ans_div_c+=1;
		} ans_div_c+=1 ans_div_c 1 if (A%D==0) {
			ans_div_d+=1;
		} A%D==0 A%D A D 0 {
			ans_div_d+=1;
		} ans_div_d+=1 ans_div_d 1 if (A%cd==0) {
			ans_div_cd+=1;
		} A%cd==0 A%cd A cd 0 {
			ans_div_cd+=1;
		} ans_div_cd+=1 ans_div_cd 1 System.out.println(ans_sum-ans_div_c-ans_div_d+ans_div_cd) System.out.println System.out System System.out ans_sum-ans_div_c-ans_div_d+ans_div_cd ans_sum-ans_div_c-ans_div_d ans_sum-ans_div_c-ans_div_d ans_sum ans_div_c ans_div_d ans_div_cd String[] args args static long gcd(long a,long b) {
	    long temp;
	    while ((temp=a%b)!=0) {
	        a=b;
	        b=temp;
	    }
	    return b;
	} gcd {
	    long temp;
	    while ((temp=a%b)!=0) {
	        a=b;
	        b=temp;
	    }
	    return b;
	} long temp; temp while ((temp=a%b)!=0) {
	        a=b;
	        b=temp;
	    } (temp=a%b)!=0 (temp=a%b) temp a%b a b 0 {
	        a=b;
	        b=temp;
	    } a=b a b b=temp b temp return b; b long a a long b b
import java.util.*;

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 ans_sum=B-A+1;
		long ans_div_c=B/C-A/C;
		long ans_div_d=B/D-A/D;
		long cd=C*D/gcd(C,D);
		long ans_div_cd=B/cd-A/cd;
		if (A%C==0) {
			ans_div_c+=1;
		}
		if (A%D==0) {
			ans_div_d+=1;
		}
		if (A%cd==0) {
			ans_div_cd+=1;
		}
		System.out.println(ans_sum-ans_div_c-ans_div_d+ans_div_cd);
	}

	static long gcd(long a,long b) {
	    long temp;
	    while ((temp=a%b)!=0) {
	        a=b;
	        b=temp;
	    }
	    return b;
	}
}