

import java.util.Scanner;

public class Main {
	   static long gcd(long a, long b) 
	    { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } 
	      
	    // method to return LCM of two numbers 
	    static long lcm(long a, long b) 
	    { 
	        return (a*b)/gcd(a, b); 
	    } 
	static long find(long x,long c,long d)
	{
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	   static long gcd(long a, long b) 
	    { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } 
	      
	    // method to return LCM of two numbers 
	    static long lcm(long a, long b) 
	    { 
	        return (a*b)/gcd(a, b); 
	    } 
	static long find(long x,long c,long d)
	{
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	}
} Main static long gcd(long a, long b) 
	    { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } gcd { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } if (a == 0) 
	        return b; a == 0 a 0 return b; b return gcd(b % a, a); gcd(b % a, a) gcd b % a b a a long a a long b b // method to return LCM of two numbers 
	    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 static long find(long x,long c,long d)
	{
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	} find {
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	} long ans=0; ans 0 ans=x/d ans x/d x d ans+=x/c ans x/c x c ans-=x/lcm(c,d) ans x/lcm(c,d) x lcm(c,d) lcm c d return ans; ans long x x long c c long d d public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	} main {
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) long a=scan.nextLong(); a scan.nextLong() scan.nextLong scan long b=scan.nextLong(); b scan.nextLong() scan.nextLong scan long c=scan.nextLong(); c scan.nextLong() scan.nextLong scan long d=scan.nextLong(); d scan.nextLong() scan.nextLong scan long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d)); ans (b-find(b,c,d))-((a-1)-find(a-1,c,d)) (b-find(b,c,d)) b find(b,c,d) find b c d ((a-1)-find(a-1,c,d)) (a-1) a 1 find(a-1,c,d) find a-1 a 1 c d System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {
	   static long gcd(long a, long b) 
	    { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } 
	      
	    // method to return LCM of two numbers 
	    static long lcm(long a, long b) 
	    { 
	        return (a*b)/gcd(a, b); 
	    } 
	static long find(long x,long c,long d)
	{
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	}
} public class Main {
	   static long gcd(long a, long b) 
	    { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } 
	      
	    // method to return LCM of two numbers 
	    static long lcm(long a, long b) 
	    { 
	        return (a*b)/gcd(a, b); 
	    } 
	static long find(long x,long c,long d)
	{
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	}
} Main


import java.util.Scanner;

public class Main {
	   static long gcd(long a, long b) 
	    { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
	    } 
	      
	    // method to return LCM of two numbers 
	    static long lcm(long a, long b) 
	    { 
	        return (a*b)/gcd(a, b); 
	    } 
	static long find(long x,long c,long d)
	{
		long ans=0;
		ans=x/d;
		ans+=x/c;
		ans-=x/lcm(c,d);
		return ans;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		
		long ans=(b-find(b,c,d))-((a-1)-find(a-1,c,d));
		System.out.println(ans);
	}
}
