import java.util.Scanner;

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

public class Main {
	static long gcd(long a, long b) {
		if(a%b!=0) {
			return gcd(b,a%b);
		}else {
			return b;
		}
	}
	static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong()-1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long count = 0;
        long l=lcm(c,d);
        long bl=b/l;
        long bwaruc= b/c;
        long bwarud= b/d;
        long ansb = b-(bwaruc+bwarud)+bl;
        long al=a/l;
        long ansa = a-(a/c+a/d)+al;
        
        count=ansb-ansa;
        System.out.println(count);
    }
}
