import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	}

	public static long gcd(long c, long d) {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	}

	public static long gcd(long c, long d) {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	} main {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String str = sc.nextLine(); str sc.nextLine() sc.nextLine sc long a = Long.parseLong(str.split(" ")[0]); a Long.parseLong(str.split(" ")[0]) Long.parseLong Long str.split(" ")[0] str.split(" ") str.split str " " 0 long b = Long.parseLong(str.split(" ")[1]); b Long.parseLong(str.split(" ")[1]) Long.parseLong Long str.split(" ")[1] str.split(" ") str.split str " " 1 long c = Long.parseLong(str.split(" ")[2]); c Long.parseLong(str.split(" ")[2]) Long.parseLong Long str.split(" ")[2] str.split(" ") str.split str " " 2 long d = Long.parseLong(str.split(" ")[3]); d Long.parseLong(str.split(" ")[3]) Long.parseLong Long str.split(" ")[3] str.split(" ") str.split str " " 3 long ans = 0; ans 0 long anti_c = (long)(b/c) - (long)((a-1)/c); anti_c (long)(b/c) - (long)((a-1)/c) (long)(b/c) b c (long)((a-1)/c) (a-1) a 1 c long anti_d = (long)(b/d) - (long)((a-1)/d); anti_d (long)(b/d) - (long)((a-1)/d) (long)(b/d) b d (long)((a-1)/d) (a-1) a 1 d if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		} c==d c d {
				System.out.println(b-a+1-anti_c);
				return;
		} System.out.println(b-a+1-anti_c) System.out.println System.out System System.out b-a+1-anti_c b-a+1 b-a b a 1 anti_c return; long cd = c*d/gcd(c,d); cd c*d/gcd(c,d) c*d c d gcd(c,d) gcd c d long anti_cd = (long)(b/cd) - (long)((a-1)/cd); anti_cd (long)(b/cd) - (long)((a-1)/cd) (long)(b/cd) b cd (long)((a-1)/cd) (a-1) a 1 cd System.out.println(b-a+1-anti_c-anti_d+anti_cd) System.out.println System.out System System.out b-a+1-anti_c-anti_d+anti_cd b-a+1-anti_c-anti_d b-a+1-anti_c-anti_d b-a+1 b-a b a 1 anti_c anti_d anti_cd String[] args args public static long gcd(long c, long d) {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	} gcd {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	} long temp=0; temp 0 while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		} d%c!=0 d%c d c 0 {
			temp = d%c;
			d = c;
			c = temp;
		} temp = d%c temp d%c d c d = c d c c = temp c temp return c; c long c c long d d public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	}

	public static long gcd(long c, long d) {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	}

	public static long gcd(long c, long d) {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		long a = Long.parseLong(str.split(" ")[0]);
		long b = Long.parseLong(str.split(" ")[1]);
		long c = Long.parseLong(str.split(" ")[2]);
		long d = Long.parseLong(str.split(" ")[3]);

		long ans = 0;

		long anti_c = (long)(b/c) - (long)((a-1)/c);
		long anti_d = (long)(b/d) - (long)((a-1)/d);

		if(c==d) {
				System.out.println(b-a+1-anti_c);
				return;
		}

		long cd = c*d/gcd(c,d);
		long anti_cd = (long)(b/cd) - (long)((a-1)/cd);

		System.out.println(b-a+1-anti_c-anti_d+anti_cd);

	}

	public static long gcd(long c, long d) {
		long temp=0;
		while(d%c!=0) {
			temp = d%c;
			d = c;
			c = temp;
		}
		return c;
	}

}
