import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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();
		System.out.println(solve(b,c,d)-solve(a-1,c,d));

	}
	static long gcd(long a,long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	static long solve(long b,long c,long d) {
		long ret = b;
		long other = c*d/gcd(c,d);
		ret-= b/c;
		ret -= b/d;
		ret += b/other;
		return ret;
	}

} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util 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();
		System.out.println(solve(b,c,d)-solve(a-1,c,d));

	}
	static long gcd(long a,long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	static long solve(long b,long c,long d) {
		long ret = b;
		long other = c*d/gcd(c,d);
		ret-= b/c;
		ret -= b/d;
		ret += b/other;
		return ret;
	}

} 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();
		System.out.println(solve(b,c,d)-solve(a-1,c,d));

	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		System.out.println(solve(b,c,d)-solve(a-1,c,d));

	} 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 System.out.println(solve(b,c,d)-solve(a-1,c,d)) System.out.println System.out System System.out solve(b,c,d)-solve(a-1,c,d) solve(b,c,d) solve b c d solve(a-1,c,d) solve a-1 a 1 c d String[] args args static long gcd(long a,long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	} gcd {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	} 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 static long solve(long b,long c,long d) {
		long ret = b;
		long other = c*d/gcd(c,d);
		ret-= b/c;
		ret -= b/d;
		ret += b/other;
		return ret;
	} solve {
		long ret = b;
		long other = c*d/gcd(c,d);
		ret-= b/c;
		ret -= b/d;
		ret += b/other;
		return ret;
	} long ret = b; ret b long other = c*d/gcd(c,d); other c*d/gcd(c,d) c*d c d gcd(c,d) gcd c d ret-= b/c ret b/c b c ret -= b/d ret b/d b d ret += b/other ret b/other b other return ret; ret long b b long c c long d d 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();
		System.out.println(solve(b,c,d)-solve(a-1,c,d));

	}
	static long gcd(long a,long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	static long solve(long b,long c,long d) {
		long ret = b;
		long other = c*d/gcd(c,d);
		ret-= b/c;
		ret -= b/d;
		ret += b/other;
		return ret;
	}

} 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();
		System.out.println(solve(b,c,d)-solve(a-1,c,d));

	}
	static long gcd(long a,long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	static long solve(long b,long c,long d) {
		long ret = b;
		long other = c*d/gcd(c,d);
		ret-= b/c;
		ret -= b/d;
		ret += b/other;
		return ret;
	}

} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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();
		System.out.println(solve(b,c,d)-solve(a-1,c,d));

	}
	static long gcd(long a,long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	static long solve(long b,long c,long d) {
		long ret = b;
		long other = c*d/gcd(c,d);
		ret-= b/c;
		ret -= b/d;
		ret += b/other;
		return ret;
	}

}
