import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong()-1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		//最大公約数
		long plese = (C*D)/gcd(C, D);

		long n = (B-(B/C+B/D))+(B/plese);
		long m = (A-(A/C+A/D))+(A/plese);
		long anser = (n-m);
		System.out.println(anser);
	}
	private static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		a = a%b;
		return gcd(b,a);
	}

} 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()-1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		//最大公約数
		long plese = (C*D)/gcd(C, D);

		long n = (B-(B/C+B/D))+(B/plese);
		long m = (A-(A/C+A/D))+(A/plese);
		long anser = (n-m);
		System.out.println(anser);
	}
	private static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		a = a%b;
		return gcd(b,a);
	}

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

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong()-1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		//最大公約数
		long plese = (C*D)/gcd(C, D);

		long n = (B-(B/C+B/D))+(B/plese);
		long m = (A-(A/C+A/D))+(A/plese);
		long anser = (n-m);
		System.out.println(anser);
	} main {

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong()-1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		//最大公約数
		long plese = (C*D)/gcd(C, D);

		long n = (B-(B/C+B/D))+(B/plese);
		long m = (A-(A/C+A/D))+(A/plese);
		long anser = (n-m);
		System.out.println(anser);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = sc.nextLong()-1; A sc.nextLong()-1 sc.nextLong() sc.nextLong sc 1 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 long plese = (C*D)/gcd(C, D); plese (C*D)/gcd(C, D) (C*D) C D gcd(C, D) gcd C D long n = (B-(B/C+B/D))+(B/plese); n (B-(B/C+B/D))+(B/plese) (B-(B/C+B/D)) B (B/C+B/D) B/C B C B/D B D (B/plese) B plese long m = (A-(A/C+A/D))+(A/plese); m (A-(A/C+A/D))+(A/plese) (A-(A/C+A/D)) A (A/C+A/D) A/C A C A/D A D (A/plese) A plese long anser = (n-m); anser (n-m) n m System.out.println(anser) System.out.println System.out System System.out anser String[] args args private static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		a = a%b;
		return gcd(b,a);
	} gcd {
		if(b==0) {
			return a;
		}
		a = a%b;
		return gcd(b,a);
	} if(b==0) {
			return a;
		} b==0 b 0 {
			return a;
		} return a; a a = a%b a a%b a b return gcd(b,a); gcd(b,a) gcd b a 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()-1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		//最大公約数
		long plese = (C*D)/gcd(C, D);

		long n = (B-(B/C+B/D))+(B/plese);
		long m = (A-(A/C+A/D))+(A/plese);
		long anser = (n-m);
		System.out.println(anser);
	}
	private static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		a = a%b;
		return gcd(b,a);
	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong()-1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		//最大公約数
		long plese = (C*D)/gcd(C, D);

		long n = (B-(B/C+B/D))+(B/plese);
		long m = (A-(A/C+A/D))+(A/plese);
		long anser = (n-m);
		System.out.println(anser);
	}
	private static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		a = a%b;
		return gcd(b,a);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong()-1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		//最大公約数
		long plese = (C*D)/gcd(C, D);

		long n = (B-(B/C+B/D))+(B/plese);
		long m = (A-(A/C+A/D))+(A/plese);
		long anser = (n-m);
		System.out.println(anser);
	}
	private static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		a = a%b;
		return gcd(b,a);
	}

}
