import java.util.Scanner;

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

		Scanner sysin = new Scanner(System.in);
		final long a = sysin.nextLong();
		final long b = sysin.nextLong();
		final long c = sysin.nextLong();
		final long d = sysin.nextLong();
		sysin.close();

		
		long min = a - 1;
		long max = b;
		long lowerDivisor = Math.min(c, d);
		long higherDivisor = Math.max(c, d);
		
		long factor1 = max / lowerDivisor - min / lowerDivisor;
		long factor2 = max / higherDivisor - min / higherDivisor;

		long gcd = gcd(higherDivisor, lowerDivisor);
		long lcm = lowerDivisor * higherDivisor / gcd;
		long dup = max / lcm - min / lcm;

		System.out.println(max - min - factor1 - factor2 + dup);
	}

	private static long gcd(long higher, long lower) {
		return (lower == 0) ? higher : gcd(lower, higher % lower);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		Scanner sysin = new Scanner(System.in);
		final long a = sysin.nextLong();
		final long b = sysin.nextLong();
		final long c = sysin.nextLong();
		final long d = sysin.nextLong();
		sysin.close();

		
		long min = a - 1;
		long max = b;
		long lowerDivisor = Math.min(c, d);
		long higherDivisor = Math.max(c, d);
		
		long factor1 = max / lowerDivisor - min / lowerDivisor;
		long factor2 = max / higherDivisor - min / higherDivisor;

		long gcd = gcd(higherDivisor, lowerDivisor);
		long lcm = lowerDivisor * higherDivisor / gcd;
		long dup = max / lcm - min / lcm;

		System.out.println(max - min - factor1 - factor2 + dup);
	}

	private static long gcd(long higher, long lower) {
		return (lower == 0) ? higher : gcd(lower, higher % lower);
	}
} Main public static void main(String[] args) {

		Scanner sysin = new Scanner(System.in);
		final long a = sysin.nextLong();
		final long b = sysin.nextLong();
		final long c = sysin.nextLong();
		final long d = sysin.nextLong();
		sysin.close();

		
		long min = a - 1;
		long max = b;
		long lowerDivisor = Math.min(c, d);
		long higherDivisor = Math.max(c, d);
		
		long factor1 = max / lowerDivisor - min / lowerDivisor;
		long factor2 = max / higherDivisor - min / higherDivisor;

		long gcd = gcd(higherDivisor, lowerDivisor);
		long lcm = lowerDivisor * higherDivisor / gcd;
		long dup = max / lcm - min / lcm;

		System.out.println(max - min - factor1 - factor2 + dup);
	} main {

		Scanner sysin = new Scanner(System.in);
		final long a = sysin.nextLong();
		final long b = sysin.nextLong();
		final long c = sysin.nextLong();
		final long d = sysin.nextLong();
		sysin.close();

		
		long min = a - 1;
		long max = b;
		long lowerDivisor = Math.min(c, d);
		long higherDivisor = Math.max(c, d);
		
		long factor1 = max / lowerDivisor - min / lowerDivisor;
		long factor2 = max / higherDivisor - min / higherDivisor;

		long gcd = gcd(higherDivisor, lowerDivisor);
		long lcm = lowerDivisor * higherDivisor / gcd;
		long dup = max / lcm - min / lcm;

		System.out.println(max - min - factor1 - factor2 + dup);
	} Scanner sysin = new Scanner(System.in); sysin new Scanner(System.in) final long a = sysin.nextLong(); a sysin.nextLong() sysin.nextLong sysin final long b = sysin.nextLong(); b sysin.nextLong() sysin.nextLong sysin final long c = sysin.nextLong(); c sysin.nextLong() sysin.nextLong sysin final long d = sysin.nextLong(); d sysin.nextLong() sysin.nextLong sysin sysin.close() sysin.close sysin long min = a - 1; min a - 1 a 1 long max = b; max b long lowerDivisor = Math.min(c, d); lowerDivisor Math.min(c, d) Math.min Math c d long higherDivisor = Math.max(c, d); higherDivisor Math.max(c, d) Math.max Math c d long factor1 = max / lowerDivisor - min / lowerDivisor; factor1 max / lowerDivisor - min / lowerDivisor max / lowerDivisor max lowerDivisor min / lowerDivisor min lowerDivisor long factor2 = max / higherDivisor - min / higherDivisor; factor2 max / higherDivisor - min / higherDivisor max / higherDivisor max higherDivisor min / higherDivisor min higherDivisor long gcd = gcd(higherDivisor, lowerDivisor); gcd gcd(higherDivisor, lowerDivisor) gcd higherDivisor lowerDivisor long lcm = lowerDivisor * higherDivisor / gcd; lcm lowerDivisor * higherDivisor / gcd lowerDivisor * higherDivisor lowerDivisor higherDivisor gcd long dup = max / lcm - min / lcm; dup max / lcm - min / lcm max / lcm max lcm min / lcm min lcm System.out.println(max - min - factor1 - factor2 + dup) System.out.println System.out System System.out max - min - factor1 - factor2 + dup max - min - factor1 - factor2 factor1 max - min - factor1 - factor2 max min factor1 factor2 dup String[] args args private static long gcd(long higher, long lower) {
		return (lower == 0) ? higher : gcd(lower, higher % lower);
	} gcd {
		return (lower == 0) ? higher : gcd(lower, higher % lower);
	} return (lower == 0) ? higher : gcd(lower, higher % lower); (lower == 0) ? higher : gcd(lower, higher % lower) (lower == 0) lower 0 higher gcd(lower, higher % lower) gcd lower higher % lower higher lower long higher higher long lower lower public class Main {
	public static void main(String[] args) {

		Scanner sysin = new Scanner(System.in);
		final long a = sysin.nextLong();
		final long b = sysin.nextLong();
		final long c = sysin.nextLong();
		final long d = sysin.nextLong();
		sysin.close();

		
		long min = a - 1;
		long max = b;
		long lowerDivisor = Math.min(c, d);
		long higherDivisor = Math.max(c, d);
		
		long factor1 = max / lowerDivisor - min / lowerDivisor;
		long factor2 = max / higherDivisor - min / higherDivisor;

		long gcd = gcd(higherDivisor, lowerDivisor);
		long lcm = lowerDivisor * higherDivisor / gcd;
		long dup = max / lcm - min / lcm;

		System.out.println(max - min - factor1 - factor2 + dup);
	}

	private static long gcd(long higher, long lower) {
		return (lower == 0) ? higher : gcd(lower, higher % lower);
	}
} public class Main {
	public static void main(String[] args) {

		Scanner sysin = new Scanner(System.in);
		final long a = sysin.nextLong();
		final long b = sysin.nextLong();
		final long c = sysin.nextLong();
		final long d = sysin.nextLong();
		sysin.close();

		
		long min = a - 1;
		long max = b;
		long lowerDivisor = Math.min(c, d);
		long higherDivisor = Math.max(c, d);
		
		long factor1 = max / lowerDivisor - min / lowerDivisor;
		long factor2 = max / higherDivisor - min / higherDivisor;

		long gcd = gcd(higherDivisor, lowerDivisor);
		long lcm = lowerDivisor * higherDivisor / gcd;
		long dup = max / lcm - min / lcm;

		System.out.println(max - min - factor1 - factor2 + dup);
	}

	private static long gcd(long higher, long lower) {
		return (lower == 0) ? higher : gcd(lower, higher % lower);
	}
} Main
import java.util.Scanner;

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

		Scanner sysin = new Scanner(System.in);
		final long a = sysin.nextLong();
		final long b = sysin.nextLong();
		final long c = sysin.nextLong();
		final long d = sysin.nextLong();
		sysin.close();

		
		long min = a - 1;
		long max = b;
		long lowerDivisor = Math.min(c, d);
		long higherDivisor = Math.max(c, d);
		
		long factor1 = max / lowerDivisor - min / lowerDivisor;
		long factor2 = max / higherDivisor - min / higherDivisor;

		long gcd = gcd(higherDivisor, lowerDivisor);
		long lcm = lowerDivisor * higherDivisor / gcd;
		long dup = max / lcm - min / lcm;

		System.out.println(max - min - factor1 - factor2 + dup);
	}

	private static long gcd(long higher, long lower) {
		return (lower == 0) ? higher : gcd(lower, higher % lower);
	}
}
