
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long c=scn.nextLong();
		long d=scn.nextLong();
		if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		}
	}
	static long lcm(long a, long b){
		return a / gcd(a,b) * b;
	}
	static long gcd(long a, long b){
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long c=scn.nextLong();
		long d=scn.nextLong();
		if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		}
	}
	static long lcm(long a, long b){
		return a / gcd(a,b) * b;
	}
	static long gcd(long a, long b){
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long c=scn.nextLong();
		long d=scn.nextLong();
		if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		}
	} main {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long c=scn.nextLong();
		long d=scn.nextLong();
		if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		}
	} Scanner scn=new Scanner(System.in); scn new Scanner(System.in) long a=scn.nextLong(); a scn.nextLong() scn.nextLong scn long b=scn.nextLong(); b scn.nextLong() scn.nextLong scn long c=scn.nextLong(); c scn.nextLong() scn.nextLong scn long d=scn.nextLong(); d scn.nextLong() scn.nextLong scn if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		} c%d==0 c%d c d 0 {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		} if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			} d>a d a {
				System.out.println(b-a+1-(b/d));
			} System.out.println(b-a+1-(b/d)) System.out.println System.out System System.out b-a+1-(b/d) b-a+1 b-a b a 1 (b/d) b d {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			} System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1))) System.out.println System.out System System.out b-a+1-(b/d-a/d+(a%d!=0?0:1)) b-a+1 b-a b a 1 (b/d-a/d+(a%d!=0?0:1)) b/d-a/d b/d b d a/d a d (a%d!=0?0:1) a%d!=0 a%d a d 0 0 1 if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		} d%c==0 d%c d c 0 {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		} if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			} c>a c a {
				System.out.println(b-a+1-(b/c));
			} System.out.println(b-a+1-(b/c)) System.out.println System.out System System.out b-a+1-(b/c) b-a+1 b-a b a 1 (b/c) b c {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			} System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))) System.out.println System.out System System.out b-a+1-(b/c-a/c+(a%c!=0?0:1)) b-a+1 b-a b a 1 (b/c-a/c+(a%c!=0?0:1)) b/c-a/c b/c b c a/c a c (a%c!=0?0:1) a%c!=0 a%c a c 0 0 1 {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		} if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			} c>a&&d>a c>a c a d>a d a {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			} System.out.println(b-a+1-b/c-b/d+b/(c*d)) System.out.println System.out System System.out b-a+1-b/c-b/d+b/(c*d) b-a+1-b/c-b/d b-a+1-b/c-b/d b-a+1 b-a b a 1 b/c b c b/d b d b/(c*d) b (c*d) c d if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			} c>a c a {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			} System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d)) System.out.println System.out System System.out b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d) b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1)) b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1)) b-a+1 b-a b a 1 b/c b c (b/d-a/d+(a%d!=0?0:1)) b/d-a/d b/d b d a/d a d (a%d!=0?0:1) a%d!=0 a%d a d 0 0 1 b/(c*d) b (c*d) c d if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			} d>a d a {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			} System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d)) System.out.println System.out System System.out b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d) b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d b-a+1 b-a b a 1 (b/c-a/c+(a%c!=0?0:1)) b/c-a/c b/c b c a/c a c (a%c!=0?0:1) a%c!=0 a%c a c 0 0 1 b/d b d b/(c*d) b (c*d) c d {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			} System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1))) System.out.println System.out System System.out (long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)) b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d)) b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d)) b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1)) b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1)) b-a+1 b-a b a 1 (b/c-a/c+(a%c!=0?0:1)) b/c-a/c b/c b c a/c a c (a%c!=0?0:1) a%c!=0 a%c a c 0 0 1 (b/d-a/d+(a%d!=0?0:1)) b/d-a/d b/d b d a/d a d (a%d!=0?0:1) a%d!=0 a%d a d 0 0 1 b/(lcm(c,d)) b (lcm(c,d)) lcm c d a/(lcm(c,d)) a (lcm(c,d)) lcm c d ((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1) (a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d) (a%(lcm(c,d))!=0&&a>c*d) a%(lcm(c,d))!=0 a%(lcm(c,d)) a (lcm(c,d)) lcm c d 0 a>c*d a c*d c d a<lcm(c,d) a lcm(c,d) lcm c d 0 1 String[] args args static long lcm(long a, long b){
		return a / gcd(a,b) * b;
	} lcm {
		return a / gcd(a,b) * b;
	} return a / gcd(a,b) * b; a / gcd(a,b) * b a / gcd(a,b) a gcd(a,b) gcd a b b long a a long b b static long gcd(long a, long b){
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	} gcd {
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	} if(a<b){
			a^=b;
			b^=a;
			a^=b;
		} a<b a b {
			a^=b;
			b^=a;
			a^=b;
		} a^=b a b b^=a b a a^=b a b if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		} a%b==0 a%b a b 0 {
			return b;
		} return b; b {
			return gcd(b,a%b);
		} return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long c=scn.nextLong();
		long d=scn.nextLong();
		if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		}
	}
	static long lcm(long a, long b){
		return a / gcd(a,b) * b;
	}
	static long gcd(long a, long b){
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	}
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long c=scn.nextLong();
		long d=scn.nextLong();
		if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		}
	}
	static long lcm(long a, long b){
		return a / gcd(a,b) * b;
	}
	static long gcd(long a, long b){
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long c=scn.nextLong();
		long d=scn.nextLong();
		if(c%d==0) {
			if(d>a) {
				System.out.println(b-a+1-(b/d));
			}else {
				System.out.println(b-a+1-(b/d-a/d+(a%d!=0?0:1)));
			}
		}else if(d%c==0) {
			if(c>a) {
				System.out.println(b-a+1-(b/c));
			}else {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1)));
			}
		}else {
			if(c>a&&d>a) {
				System.out.println(b-a+1-b/c-b/d+b/(c*d));

			}else if(c>a) {
				System.out.println(b-a+1-b/c-(b/d-a/d+(a%d!=0?0:1))+b/(c*d));

			}else if(d>a) {
				System.out.println(b-a+1-(b/c-a/c+(a%c!=0?0:1))-b/d+b/(c*d));

			}else {
				System.out.println((long)(b-a+1-(b/c-a/c+(a%c!=0?0:1))-(b/d-a/d+(a%d!=0?0:1))+b/(lcm(c,d))-a/(lcm(c,d))+((a%(lcm(c,d))!=0&&a>c*d)||a<lcm(c,d)?0:1)));

			}
		}
	}
	static long lcm(long a, long b){
		return a / gcd(a,b) * b;
	}
	static long gcd(long a, long b){
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	}
}
