import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int count=0;
		long l=lcm(c,d);
		System.out.println(b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d-(a-1)/l);
	}

	private static long lcm(long m,long n){
		return m*n/gcd(m,n);
	}

	private static long gcd(long m,long n){
		if(m<n)return gcd(n,m);
		if(n==0) return m;
		return gcd(n,m%n);
	}
} import java.util.*; util.* java class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int count=0;
		long l=lcm(c,d);
		System.out.println(b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d-(a-1)/l);
	}

	private static long lcm(long m,long n){
		return m*n/gcd(m,n);
	}

	private static long gcd(long m,long n){
		if(m<n)return gcd(n,m);
		if(n==0) return m;
		return gcd(n,m%n);
	}
} Main public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int count=0;
		long l=lcm(c,d);
		System.out.println(b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d-(a-1)/l);
	} main {
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int count=0;
		long l=lcm(c,d);
		System.out.println(b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d-(a-1)/l);
	} 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 int c=sc.nextInt(); c sc.nextInt() sc.nextInt sc int d=sc.nextInt(); d sc.nextInt() sc.nextInt sc int count=0; count 0 long l=lcm(c,d); l lcm(c,d) lcm c d System.out.println(b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d-(a-1)/l) System.out.println System.out System System.out b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d-(a-1)/l b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d (a-1)/c b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d b-b/c-b/d+b/l-a b-b/c-b/d+b/l b-b/c-b/d b-b/c-b/d b b/c b c b/d b d b/l b l a 1 (a-1)/c (a-1) a 1 c (a-1)/d (a-1) a 1 d (a-1)/l (a-1) a 1 l String[] args args private static long lcm(long m,long n){
		return m*n/gcd(m,n);
	} lcm {
		return m*n/gcd(m,n);
	} return m*n/gcd(m,n); m*n/gcd(m,n) m*n m n gcd(m,n) gcd m n long m m long n n private static long gcd(long m,long n){
		if(m<n)return gcd(n,m);
		if(n==0) return m;
		return gcd(n,m%n);
	} gcd {
		if(m<n)return gcd(n,m);
		if(n==0) return m;
		return gcd(n,m%n);
	} if(m<n)return gcd(n,m); m<n m n return gcd(n,m); gcd(n,m) gcd n m if(n==0) return m; n==0 n 0 return m; m return gcd(n,m%n); gcd(n,m%n) gcd n m%n m n long m m long n n
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int count=0;
		long l=lcm(c,d);
		System.out.println(b-b/c-b/d+b/l-a+1+(a-1)/c+(a-1)/d-(a-1)/l);
	}

	private static long lcm(long m,long n){
		return m*n/gcd(m,n);
	}

	private static long gcd(long m,long n){
		if(m<n)return gcd(n,m);
		if(n==0) return m;
		return gcd(n,m%n);
	}
}