import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	}
	
	public static long gcd(long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
}
	 import java.util.*; util.* java import java.io.*; io.* java public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	}
	
	public static long gcd(long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
} Main public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	} main {
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	} Scanner in=new Scanner(System.in); in new Scanner(System.in) long a=in.nextLong(); a in.nextLong() in.nextLong in long b=in.nextLong(); b in.nextLong() in.nextLong in long c=in.nextLong(); c in.nextLong() in.nextLong in long d=in.nextLong(); d in.nextLong() in.nextLong in long g=gcd(c,d); g gcd(c,d) gcd c d long q=c*d/g; q c*d/g c*d c d g long ans=b/c-(a-1)/c; ans b/c-(a-1)/c b/c b c (a-1)/c (a-1) a 1 c ans=ans+b/d-(a-1)/d ans ans+b/d-(a-1)/d ans+b/d ans b/d b d (a-1)/d (a-1) a 1 d ans=ans-b/q+(a-1)/q ans ans-b/q+(a-1)/q ans-b/q ans b/q b q (a-1)/q (a-1) a 1 q ans=b-a-ans+1 ans b-a-ans+1 b-a-ans b-a-ans b a ans 1 System.out.println(ans) System.out.println System.out System System.out ans String [] Args Args public static long gcd(long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	} gcd {
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	} if(a%b==0)
			return b; a%b==0 a%b a b 0 return b; b return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	}
	
	public static long gcd(long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
} public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	}
	
	public static long gcd(long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
} Main
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	}
	
	public static long gcd(long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
}
	