import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	}

	private static long gcd(long a,long b) {
		if(a < b) {
			return gcd(b, a);
		}
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	} main {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = sc.nextLong(); A sc.nextLong() sc.nextLong sc long B = sc.nextLong(); B sc.nextLong() sc.nextLong sc long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc sc.close() sc.close sc long lcm =C*D/gcd(C,D); lcm C*D/gcd(C,D) C*D C D gcd(C,D) gcd C D long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm; sumA (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm (A-1) - (A-1)/C -(A-1)/D (A-1) - (A-1)/C -(A-1)/D (A-1) A 1 (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/lcm (A-1) A 1 lcm long sumB = B - B/C -B/D + B/lcm; sumB B - B/C -B/D + B/lcm B - B/C -B/D B - B/C -B/D B B/C B C B/D B D B/lcm B lcm System.out.println(sumB - sumA) System.out.println System.out System System.out sumB - sumA sumB sumA String[] args args private static long gcd(long a,long b) {
		if(a < b) {
			return gcd(b, a);
		}
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	} gcd {
		if(a < b) {
			return gcd(b, a);
		}
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	} if(a < b) {
			return gcd(b, a);
		} a < b a b {
			return gcd(b, a);
		} return gcd(b, a); gcd(b, a) gcd b a if(b==0) {
			return a;
		} b==0 b 0 {
			return a;
		} return a; a 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) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	}

	private static long gcd(long a,long b) {
		if(a < b) {
			return gcd(b, a);
		}
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	}

	private static long gcd(long a,long b) {
		if(a < b) {
			return gcd(b, a);
		}
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	}

	private static long gcd(long a,long b) {
		if(a < b) {
			return gcd(b, a);
		}
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
}