import java.util.*;

public class Main {

	static long gcd(long x,long y) {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	}
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} 	
}
//end import java.util.*; util.* java public class Main {

	static long gcd(long x,long y) {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	}
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} 	
} Main static long gcd(long x,long y) {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	} gcd {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	} if (x<y)gcd(y,x); x<y x y gcd(y,x) gcd y x if (y%x==0)return x; y%x==0 y%x y x 0 return x; x return gcd(y,x%y); gcd(y,x%y) gcd y x%y x y long x x long y y public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} main {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a=Long.parseLong(scan.next()); a Long.parseLong(scan.next()) Long.parseLong Long scan.next() scan.next scan long b=Long.parseLong(scan.next()); b Long.parseLong(scan.next()) Long.parseLong Long scan.next() scan.next scan long c=Long.parseLong(scan.next()); c Long.parseLong(scan.next()) Long.parseLong Long scan.next() scan.next scan long d=Long.parseLong(scan.next()); d Long.parseLong(scan.next()) Long.parseLong Long scan.next() scan.next scan long lcm=c*d/gcd(c,d); lcm c*d/gcd(c,d) c*d c d gcd(c,d) gcd c d --a a long ans1=a/c+a/d-a/lcm; ans1 a/c+a/d-a/lcm a/c+a/d a/c a c a/d a d a/lcm a lcm ans1=a-ans1 ans1 a-ans1 a ans1 long ans2=b/c+b/d-b/lcm; ans2 b/c+b/d-b/lcm b/c+b/d b/c b c b/d b d b/lcm b lcm ans2=b-ans2 ans2 b-ans2 b ans2 System.out.print(ans2-ans1) System.out.print System.out System System.out ans2-ans1 ans2 ans1 String[] args args public class Main {

	static long gcd(long x,long y) {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	}
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} 	
} public class Main {

	static long gcd(long x,long y) {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	}
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} 	
} Main
import java.util.*;

public class Main {

	static long gcd(long x,long y) {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	}
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} 	
}
//end