import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long lc=0,rc=0,sumc=0,ld=0,rd=0,sumd=0,lcd=0,rcd=0,sumcd=0,res=0;
		long lcm=0;
		if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c);

		lc=(a-1)/c;
		rc=b/c;
		sumc=rc-lc;

		ld=(a-1)/d;
		rd=b/d;
		sumd=rd-ld;

		lcd=(a-1)/lcm;
		rcd=b/lcm;
		sumcd=rcd-lcd;

		res=sumc+sumd-sumcd;
		System.out.println((b-a+1)-res);
	//	System.out.println(sumc+" "+sumd+" "+sumcd+" "+res);
	//	System.out.println(lc+" "+rc+" "+ld+" "+rd+" "+lcd+" "+rcd);
	}
	/*min,maxの最大公約数を求める。引数の大小は気を付ける*/
	public static long GCD(long min,long max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	}
	/*min,maxの最小公倍数を求める。GCDとセットで使うように。引数の大小は気を付ける*/
	public static long LCM(long min,long max) {
		return (min*max)/GCD(min,max);
	}
}
 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(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long lc=0,rc=0,sumc=0,ld=0,rd=0,sumd=0,lcd=0,rcd=0,sumcd=0,res=0;
		long lcm=0;
		if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c);

		lc=(a-1)/c;
		rc=b/c;
		sumc=rc-lc;

		ld=(a-1)/d;
		rd=b/d;
		sumd=rd-ld;

		lcd=(a-1)/lcm;
		rcd=b/lcm;
		sumcd=rcd-lcd;

		res=sumc+sumd-sumcd;
		System.out.println((b-a+1)-res);
	//	System.out.println(sumc+" "+sumd+" "+sumcd+" "+res);
	//	System.out.println(lc+" "+rc+" "+ld+" "+rd+" "+lcd+" "+rcd);
	}
	/*min,maxの最大公約数を求める。引数の大小は気を付ける*/
	public static long GCD(long min,long max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	}
	/*min,maxの最小公倍数を求める。GCDとセットで使うように。引数の大小は気を付ける*/
	public static long LCM(long min,long max) {
		return (min*max)/GCD(min,max);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long lc=0,rc=0,sumc=0,ld=0,rd=0,sumd=0,lcd=0,rcd=0,sumcd=0,res=0;
		long lcm=0;
		if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c);

		lc=(a-1)/c;
		rc=b/c;
		sumc=rc-lc;

		ld=(a-1)/d;
		rd=b/d;
		sumd=rd-ld;

		lcd=(a-1)/lcm;
		rcd=b/lcm;
		sumcd=rcd-lcd;

		res=sumc+sumd-sumcd;
		System.out.println((b-a+1)-res);
	//	System.out.println(sumc+" "+sumd+" "+sumcd+" "+res);
	//	System.out.println(lc+" "+rc+" "+ld+" "+rd+" "+lcd+" "+rcd);
	} main {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long lc=0,rc=0,sumc=0,ld=0,rd=0,sumd=0,lcd=0,rcd=0,sumcd=0,res=0;
		long lcm=0;
		if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c);

		lc=(a-1)/c;
		rc=b/c;
		sumc=rc-lc;

		ld=(a-1)/d;
		rd=b/d;
		sumd=rd-ld;

		lcd=(a-1)/lcm;
		rcd=b/lcm;
		sumcd=rcd-lcd;

		res=sumc+sumd-sumcd;
		System.out.println((b-a+1)-res);
	//	System.out.println(sumc+" "+sumd+" "+sumcd+" "+res);
	//	System.out.println(lc+" "+rc+" "+ld+" "+rd+" "+lcd+" "+rcd);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 lc=0 lc 0 rc=0 rc 0 sumc=0 sumc 0 ld=0 ld 0 rd=0 rd 0 sumd=0 sumd 0 lcd=0 lcd 0 rcd=0 rcd 0 sumcd=0 sumcd 0 res=0; res 0 long lcm=0; lcm 0 if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c); c<d c d lcm=LCM(c,d) lcm LCM(c,d) LCM c d lcm=LCM(d,c) lcm LCM(d,c) LCM d c lc=(a-1)/c lc (a-1)/c (a-1) a 1 c rc=b/c rc b/c b c sumc=rc-lc sumc rc-lc rc lc ld=(a-1)/d ld (a-1)/d (a-1) a 1 d rd=b/d rd b/d b d sumd=rd-ld sumd rd-ld rd ld lcd=(a-1)/lcm lcd (a-1)/lcm (a-1) a 1 lcm rcd=b/lcm rcd b/lcm b lcm sumcd=rcd-lcd sumcd rcd-lcd rcd lcd res=sumc+sumd-sumcd res sumc+sumd-sumcd sumc+sumd sumc sumd sumcd System.out.println((b-a+1)-res) System.out.println System.out System System.out (b-a+1)-res (b-a+1) b-a b a 1 res String[] args args /*min,maxの最大公約数を求める。引数の大小は気を付ける*/
	public static long GCD(long min,long max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	} GCD {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	} if(max%min==0)return min;
		else return GCD(max%min,min); max%min==0 max%min max min 0 return min; min return GCD(max%min,min); GCD(max%min,min) GCD max%min max min min long min min long max max /*min,maxの最小公倍数を求める。GCDとセットで使うように。引数の大小は気を付ける*/
	public static long LCM(long min,long max) {
		return (min*max)/GCD(min,max);
	} LCM {
		return (min*max)/GCD(min,max);
	} return (min*max)/GCD(min,max); (min*max)/GCD(min,max) (min*max) min max GCD(min,max) GCD min max long min min long max max public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long lc=0,rc=0,sumc=0,ld=0,rd=0,sumd=0,lcd=0,rcd=0,sumcd=0,res=0;
		long lcm=0;
		if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c);

		lc=(a-1)/c;
		rc=b/c;
		sumc=rc-lc;

		ld=(a-1)/d;
		rd=b/d;
		sumd=rd-ld;

		lcd=(a-1)/lcm;
		rcd=b/lcm;
		sumcd=rcd-lcd;

		res=sumc+sumd-sumcd;
		System.out.println((b-a+1)-res);
	//	System.out.println(sumc+" "+sumd+" "+sumcd+" "+res);
	//	System.out.println(lc+" "+rc+" "+ld+" "+rd+" "+lcd+" "+rcd);
	}
	/*min,maxの最大公約数を求める。引数の大小は気を付ける*/
	public static long GCD(long min,long max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	}
	/*min,maxの最小公倍数を求める。GCDとセットで使うように。引数の大小は気を付ける*/
	public static long LCM(long min,long max) {
		return (min*max)/GCD(min,max);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long lc=0,rc=0,sumc=0,ld=0,rd=0,sumd=0,lcd=0,rcd=0,sumcd=0,res=0;
		long lcm=0;
		if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c);

		lc=(a-1)/c;
		rc=b/c;
		sumc=rc-lc;

		ld=(a-1)/d;
		rd=b/d;
		sumd=rd-ld;

		lcd=(a-1)/lcm;
		rcd=b/lcm;
		sumcd=rcd-lcd;

		res=sumc+sumd-sumcd;
		System.out.println((b-a+1)-res);
	//	System.out.println(sumc+" "+sumd+" "+sumcd+" "+res);
	//	System.out.println(lc+" "+rc+" "+ld+" "+rd+" "+lcd+" "+rcd);
	}
	/*min,maxの最大公約数を求める。引数の大小は気を付ける*/
	public static long GCD(long min,long max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	}
	/*min,maxの最小公倍数を求める。GCDとセットで使うように。引数の大小は気を付ける*/
	public static long LCM(long min,long max) {
		return (min*max)/GCD(min,max);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
		long lc=0,rc=0,sumc=0,ld=0,rd=0,sumd=0,lcd=0,rcd=0,sumcd=0,res=0;
		long lcm=0;
		if(c<d)lcm=LCM(c,d);
		else lcm=LCM(d,c);

		lc=(a-1)/c;
		rc=b/c;
		sumc=rc-lc;

		ld=(a-1)/d;
		rd=b/d;
		sumd=rd-ld;

		lcd=(a-1)/lcm;
		rcd=b/lcm;
		sumcd=rcd-lcd;

		res=sumc+sumd-sumcd;
		System.out.println((b-a+1)-res);
	//	System.out.println(sumc+" "+sumd+" "+sumcd+" "+res);
	//	System.out.println(lc+" "+rc+" "+ld+" "+rd+" "+lcd+" "+rcd);
	}
	/*min,maxの最大公約数を求める。引数の大小は気を付ける*/
	public static long GCD(long min,long max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	}
	/*min,maxの最小公倍数を求める。GCDとセットで使うように。引数の大小は気を付ける*/
	public static long LCM(long min,long max) {
		return (min*max)/GCD(min,max);
	}
}

