	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.Collections;
	import java.util.Comparator;
	import java.util.HashMap;
	import java.util.HashSet;
	import java.util.List;
	import java.util.Map;
	import java.util.Map.Entry;
	import java.util.PriorityQueue;
	import java.util.Queue;
	import java.util.Scanner;
	import java.util.Set;

	public class Main{

		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		}
		public static long gcd(long x, long y) {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		}

		public static long minbai(long x, long y) {

			return x * y / gcd(x,y);

		}

	} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.List; List java.util import java.util.Map; Map java.util import java.util.Map.Entry; Entry java.util.Map import java.util.PriorityQueue; PriorityQueue java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main{

		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		}
		public static long gcd(long x, long y) {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		}

		public static long minbai(long x, long y) {

			return x * y / gcd(x,y);

		}

	} Main public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		} main {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] t = scanner.nextLine().split(" "); t scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " long a = Long.parseLong(t[0]) - 1; a Long.parseLong(t[0]) - 1 Long.parseLong(t[0]) Long.parseLong Long t[0] t 0 1 long b = Long.parseLong(t[1]); b Long.parseLong(t[1]) Long.parseLong Long t[1] t 1 long c = Long.parseLong(t[2]); c Long.parseLong(t[2]) Long.parseLong Long t[2] t 2 long d = Long.parseLong(t[3]); d Long.parseLong(t[3]) Long.parseLong Long t[3] t 3 long m = minbai(c, d); m minbai(c, d) minbai c d long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m); adiv a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m) a - Math.floorDiv(a, c) - Math.floorDiv(a, d) a - Math.floorDiv(a, c) - Math.floorDiv(a, d) a Math.floorDiv(a, c) Math.floorDiv Math a c Math.floorDiv(a, d) Math.floorDiv Math a d Math.floorDiv(a, m) Math.floorDiv Math a m long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m); bdiv b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m) b - Math.floorDiv(b, c) - Math.floorDiv(b, d) b - Math.floorDiv(b, c) - Math.floorDiv(b, d) b Math.floorDiv(b, c) Math.floorDiv Math b c Math.floorDiv(b, d) Math.floorDiv Math b d Math.floorDiv(b, m) Math.floorDiv Math b m System.out.println(bdiv - adiv) System.out.println System.out System System.out bdiv - adiv bdiv adiv String[] args args public static long gcd(long x, long y) {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		} gcd {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		} if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			} x % y == 0 x % y x y 0 {

				return y;

			} return y; y {

				return gcd(y, x % y);

			} return gcd(y, x % y); gcd(y, x % y) gcd y x % y x y long x x long y y public static long minbai(long x, long y) {

			return x * y / gcd(x,y);

		} minbai {

			return x * y / gcd(x,y);

		} return x * y / gcd(x,y); x * y / gcd(x,y) x * y x y gcd(x,y) gcd x y long x x long y y public class Main{

		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		}
		public static long gcd(long x, long y) {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		}

		public static long minbai(long x, long y) {

			return x * y / gcd(x,y);

		}

	} public class Main{

		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		}
		public static long gcd(long x, long y) {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		}

		public static long minbai(long x, long y) {

			return x * y / gcd(x,y);

		}

	} Main
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.Collections;
	import java.util.Comparator;
	import java.util.HashMap;
	import java.util.HashSet;
	import java.util.List;
	import java.util.Map;
	import java.util.Map.Entry;
	import java.util.PriorityQueue;
	import java.util.Queue;
	import java.util.Scanner;
	import java.util.Set;

	public class Main{

		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);
			String[] t = scanner.nextLine().split(" ");
			long a = Long.parseLong(t[0]) - 1;
			long b = Long.parseLong(t[1]);
			long c = Long.parseLong(t[2]);
			long d = Long.parseLong(t[3]);
			long m = minbai(c, d);
			long adiv = a - Math.floorDiv(a, c) - Math.floorDiv(a, d) + Math.floorDiv(a, m);
			long bdiv = b - Math.floorDiv(b, c) - Math.floorDiv(b, d) + Math.floorDiv(b, m);

			System.out.println(bdiv - adiv);



		}
		public static long gcd(long x, long y) {

			if(x % y == 0) {

				return y;

			}else {

				return gcd(y, x % y);

			}

		}

		public static long minbai(long x, long y) {

			return x * y / gcd(x,y);

		}

	}