import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	}
	
	static long gcd(long a, long b) {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	}
	
	static long lcm(long a,long b,long abgcd) {
		return a * b / abgcd;
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}


 import java.util.Scanner; Scanner java.util public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	}
	
	static long gcd(long a, long b) {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	}
	
	static long lcm(long a,long b,long abgcd) {
		return a * b / abgcd;
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) void doIt() {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	} doIt {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	} long a = sc.nextLong() a sc.nextLong() sc.nextLong sc b = sc.nextLong() b sc.nextLong() sc.nextLong sc c = sc.nextLong() c sc.nextLong() sc.nextLong sc d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long cdivcnt = 0 cdivcnt 0 ddivcnt = 0 ddivcnt 0 cdboth = 0; cdboth 0 cdivcnt = b/c cdivcnt b/c b c ddivcnt = b/d ddivcnt b/d b d cdboth = b/lcm(c,d,gcd(c,d)) cdboth b/lcm(c,d,gcd(c,d)) b lcm(c,d,gcd(c,d)) lcm c d gcd(c,d) gcd c d long bcnt = b - (cdivcnt + ddivcnt) + cdboth; bcnt b - (cdivcnt + ddivcnt) + cdboth b - (cdivcnt + ddivcnt) b (cdivcnt + ddivcnt) cdivcnt ddivcnt cdboth cdivcnt = (a-1)/c cdivcnt (a-1)/c (a-1) a 1 c ddivcnt = (a-1)/d ddivcnt (a-1)/d (a-1) a 1 d cdboth = (a-1)/lcm(c,d,gcd(c,d)) cdboth (a-1)/lcm(c,d,gcd(c,d)) (a-1) a 1 lcm(c,d,gcd(c,d)) lcm c d gcd(c,d) gcd c d long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth; acnt (a-1) - (cdivcnt + ddivcnt) + cdboth (a-1) - (cdivcnt + ddivcnt) (a-1) a 1 (cdivcnt + ddivcnt) cdivcnt ddivcnt cdboth System.out.println(bcnt - acnt) System.out.println System.out System System.out bcnt - acnt bcnt acnt static long gcd(long a, long b) {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	} gcd {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	} if(a%b == 0) return b; a%b == 0 a%b a b 0 return b; b return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b static long lcm(long a,long b,long abgcd) {
		return a * b / abgcd;
	} lcm {
		return a * b / abgcd;
	} return a * b / abgcd; a * b / abgcd a * b a b abgcd long a a long b b long abgcd abgcd public static void main(String[] args) {
		new Main().doIt();
	} main {
		new Main().doIt();
	} new Main().doIt() new Main().doIt new Main() String[] args args public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	}
	
	static long gcd(long a, long b) {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	}
	
	static long lcm(long a,long b,long abgcd) {
		return a * b / abgcd;
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

} public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	}
	
	static long gcd(long a, long b) {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	}
	
	static long lcm(long a,long b,long abgcd) {
		return a * b / abgcd;
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

} Main
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	}
	
	static long gcd(long a, long b) {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	}
	
	static long lcm(long a,long b,long abgcd) {
		return a * b / abgcd;
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}



