import java.util.Scanner;

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

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        a -= 1;

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);
        System.out.println(n-m);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static long gcd(long a, long b){
		if (a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		if (b == 0) return a;
		return gcd(b, a%b);
	}

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        a -= 1;

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);
        System.out.println(n-m);
	}
} Main public static long gcd(long a, long b){
		if (a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		if (b == 0) return a;
		return gcd(b, a%b);
	} gcd {
		if (a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		if (b == 0) return a;
		return gcd(b, a%b);
	} if (a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		} a < b a b {
			long tmp = a;
			a = b;
			b = tmp;
		} long tmp = a; tmp a a = b a b b = tmp b tmp if (b == 0) return a; b == 0 b 0 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 static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        a -= 1;

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);
        System.out.println(n-m);
	} main {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        a -= 1;

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);
        System.out.println(n-m);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c = Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d = Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc a -= 1 a 1 long lcm = c * d / gcd(c,d); lcm c * d / gcd(c,d) c * d c d gcd(c,d) gcd c d long n = b - (b/c) - (b/d) + (b/lcm); n 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 long m = a - (a/c) - (a/d) + (a/lcm); m a - (a/c) - (a/d) + (a/lcm) a - (a/c) - (a/d) a - (a/c) - (a/d) a (a/c) a c (a/d) a d (a/lcm) a lcm System.out.println(n-m) System.out.println System.out System System.out n-m n m String[] args args public class Main {
	public static long gcd(long a, long b){
		if (a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		if (b == 0) return a;
		return gcd(b, a%b);
	}

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        a -= 1;

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);
        System.out.println(n-m);
	}
} public class Main {
	public static long gcd(long a, long b){
		if (a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		if (b == 0) return a;
		return gcd(b, a%b);
	}

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        a -= 1;

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);
        System.out.println(n-m);
	}
} Main
import java.util.Scanner;

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

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        a -= 1;

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);
        System.out.println(n-m);
	}
}
