import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	static long gcd(long a, long b)
	{
		return b != 0 ? gcd(b, a % b) : a;
	}
	
	static long lcm(long a, long b)
	{
		return a / gcd(a, b) * b;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		
		long cc = b / c - (a - 1) / c;
		long dd = b / d - (a - 1) / d;
		long k = lcm(c, d);
		long cd = b / k - (a - 1) / k;
		
		out.println(b - a + 1 - cc - dd + cd);
		
		out.close();
	}
	
	static class InputReader
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main
{
	static long gcd(long a, long b)
	{
		return b != 0 ? gcd(b, a % b) : a;
	}
	
	static long lcm(long a, long b)
	{
		return a / gcd(a, b) * b;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		
		long cc = b / c - (a - 1) / c;
		long dd = b / d - (a - 1) / d;
		long k = lcm(c, d);
		long cd = b / k - (a - 1) / k;
		
		out.println(b - a + 1 - cc - dd + cd);
		
		out.close();
	}
	
	static class InputReader
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
} Main static long gcd(long a, long b)
	{
		return b != 0 ? gcd(b, a % b) : a;
	} gcd {
		return b != 0 ? gcd(b, a % b) : a;
	} return b != 0 ? gcd(b, a % b) : a; b != 0 ? gcd(b, a % b) : a b != 0 b 0 gcd(b, a % b) gcd b a % b a b a long a a long b b 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 public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		
		long cc = b / c - (a - 1) / c;
		long dd = b / d - (a - 1) / d;
		long k = lcm(c, d);
		long cd = b / k - (a - 1) / k;
		
		out.println(b - a + 1 - cc - dd + cd);
		
		out.close();
	} main {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		
		long cc = b / c - (a - 1) / c;
		long dd = b / d - (a - 1) / d;
		long k = lcm(c, d);
		long cd = b / k - (a - 1) / k;
		
		out.println(b - a + 1 - cc - dd + cd);
		
		out.close();
	} InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) long a = in.nextLong(); a in.nextLong() in.nextLong in long b = in.nextLong(); b in.nextLong() in.nextLong in long c = in.nextLong(); c in.nextLong() in.nextLong in long d = in.nextLong(); d in.nextLong() in.nextLong in long cc = b / c - (a - 1) / c; cc b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long dd = b / d - (a - 1) / d; dd b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long k = lcm(c, d); k lcm(c, d) lcm c d long cd = b / k - (a - 1) / k; cd b / k - (a - 1) / k b / k b k (a - 1) / k (a - 1) a 1 k out.println(b - a + 1 - cc - dd + cd) out.println out b - a + 1 - cc - dd + cd b - a + 1 - cc - dd b - a + 1 - cc - dd b - a + 1 b - a b a 1 cc dd cd out.close() out.close out String[] args args static class InputReader
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	} InputReader BufferedReader reader; reader StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		} InputReader {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		} reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		} next {
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		} while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			} tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			} try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				} catch(IOException e)
				{
					throw new RuntimeException(e);
				} IOException e {
					throw new RuntimeException(e);
				} throw new RuntimeException(e); new RuntimeException(e) {
					tokenizer = new StringTokenizer(reader.readLine());
				} tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public int nextInt()
		{
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong()
		{
			return Long.parseLong(next());
		} nextLong {
			return Long.parseLong(next());
		} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public class Main
{
	static long gcd(long a, long b)
	{
		return b != 0 ? gcd(b, a % b) : a;
	}
	
	static long lcm(long a, long b)
	{
		return a / gcd(a, b) * b;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		
		long cc = b / c - (a - 1) / c;
		long dd = b / d - (a - 1) / d;
		long k = lcm(c, d);
		long cd = b / k - (a - 1) / k;
		
		out.println(b - a + 1 - cc - dd + cd);
		
		out.close();
	}
	
	static class InputReader
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
} public class Main
{
	static long gcd(long a, long b)
	{
		return b != 0 ? gcd(b, a % b) : a;
	}
	
	static long lcm(long a, long b)
	{
		return a / gcd(a, b) * b;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		
		long cc = b / c - (a - 1) / c;
		long dd = b / d - (a - 1) / d;
		long k = lcm(c, d);
		long cd = b / k - (a - 1) / k;
		
		out.println(b - a + 1 - cc - dd + cd);
		
		out.close();
	}
	
	static class InputReader
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	static long gcd(long a, long b)
	{
		return b != 0 ? gcd(b, a % b) : a;
	}
	
	static long lcm(long a, long b)
	{
		return a / gcd(a, b) * b;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		
		long cc = b / c - (a - 1) / c;
		long dd = b / d - (a - 1) / d;
		long k = lcm(c, d);
		long cd = b / k - (a - 1) / k;
		
		out.println(b - a + 1 - cc - dd + cd);
		
		out.close();
	}
	
	static class InputReader
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
}