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();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(a-1,c,d));

	}

static public long ans(long a,long c,long d){
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
}
static long gcd (long a, long b) {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}

static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/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();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(a-1,c,d));

	}

static public long ans(long a,long c,long d){
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
}
static long gcd (long a, long b) {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}

static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/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();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(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();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(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(ans(b,c,d)-ans(a-1,c,d)) System.out.println System.out System System.out ans(b,c,d)-ans(a-1,c,d) ans(b,c,d) ans b c d ans(a-1,c,d) ans a-1 a 1 c d String[] args args static public long ans(long a,long c,long d){
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
} ans {
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
} long han=a; han a if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	} Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17 Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d)) Math.log10(d)+Math.log10(c) Math.log10(d) Math.log10 Math d Math.log10(c) Math.log10 Math c Math.log10(gcd(c,d)) Math.log10 Math gcd(c,d) gcd c d 17 {
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	} han=han-(han/c)-(han/d)+((han/c)/d) han han-(han/c)-(han/d)+((han/c)/d) han-(han/c)-(han/d) han-(han/c)-(han/d) han (han/c) han c (han/d) han d ((han/c)/d) (han/c) han c d return han; han {
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	} han=han-(han/c)-(han/d)+(han/(lcm(c,d))) han han-(han/c)-(han/d)+(han/(lcm(c,d))) han-(han/c)-(han/d) han-(han/c)-(han/d) han (han/c) han c (han/d) han d (han/(lcm(c,d))) han (lcm(c,d)) lcm c d return han; han long a a long c c long d d static long gcd (long a, long b) {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
} gcd {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
} long temp; temp while((temp = a%b)!=0) {
		a = b;
		b = temp;
	} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
		a = b;
		b = temp;
	} a = b a b b = temp b temp return b; b long a a long b b static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/b);
} lcm {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/b);
} long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
		a = b;
		b = temp;
	} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
		a = b;
		b = temp;
	} a = b a b b = temp b temp return (long)(c/b); (long)(c/b) c 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();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(a-1,c,d));

	}

static public long ans(long a,long c,long d){
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
}
static long gcd (long a, long b) {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}

static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/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();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(a-1,c,d));

	}

static public long ans(long a,long c,long d){
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
}
static long gcd (long a, long b) {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}

static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/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();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(a-1,c,d));

	}

static public long ans(long a,long c,long d){
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
}
static long gcd (long a, long b) {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}

static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/b);
}
}
