import java.util.*;

class Main{
  
  	public static long gcd(long a,long b){
    	if(b==0)
          return a;
      	else
          return gcd(b,a%b);
    }
	public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
      long a=sc.nextLong();
      long b=sc.nextLong();
      long c=sc.nextLong();
      long d=sc.nextLong();
      
      long e=c*d/gcd(c,d);
      long sa=(b/c)-((a-1)/c);
      long sb=(b/d)-((a-1)/d);
      long sab=(b/e)-((a-1)/e);
      long diff=b-a+1-sa-sb+sab;
      System.out.print(diff);
      
    }
} import java.util.*; util.* java class Main{
  
  	public static long gcd(long a,long b){
    	if(b==0)
          return a;
      	else
          return gcd(b,a%b);
    }
	public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
      long a=sc.nextLong();
      long b=sc.nextLong();
      long c=sc.nextLong();
      long d=sc.nextLong();
      
      long e=c*d/gcd(c,d);
      long sa=(b/c)-((a-1)/c);
      long sb=(b/d)-((a-1)/d);
      long sab=(b/e)-((a-1)/e);
      long diff=b-a+1-sa-sb+sab;
      System.out.print(diff);
      
    }
} Main public static long gcd(long a,long b){
    	if(b==0)
          return a;
      	else
          return gcd(b,a%b);
    } gcd {
    	if(b==0)
          return a;
      	else
          return gcd(b,a%b);
    } if(b==0)
          return a;
      	else
          return gcd(b,a%b); b==0 b 0 return a; a return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
      long a=sc.nextLong();
      long b=sc.nextLong();
      long c=sc.nextLong();
      long d=sc.nextLong();
      
      long e=c*d/gcd(c,d);
      long sa=(b/c)-((a-1)/c);
      long sb=(b/d)-((a-1)/d);
      long sab=(b/e)-((a-1)/e);
      long diff=b-a+1-sa-sb+sab;
      System.out.print(diff);
      
    } main {
    	Scanner sc=new Scanner(System.in);
      long a=sc.nextLong();
      long b=sc.nextLong();
      long c=sc.nextLong();
      long d=sc.nextLong();
      
      long e=c*d/gcd(c,d);
      long sa=(b/c)-((a-1)/c);
      long sb=(b/d)-((a-1)/d);
      long sab=(b/e)-((a-1)/e);
      long diff=b-a+1-sa-sb+sab;
      System.out.print(diff);
      
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) long a=sc.nextLong(); a sc.nextLong() sc.nextLong sc 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 e=c*d/gcd(c,d); e c*d/gcd(c,d) c*d c d gcd(c,d) gcd c d long sa=(b/c)-((a-1)/c); sa (b/c)-((a-1)/c) (b/c) b c ((a-1)/c) (a-1) a 1 c long sb=(b/d)-((a-1)/d); sb (b/d)-((a-1)/d) (b/d) b d ((a-1)/d) (a-1) a 1 d long sab=(b/e)-((a-1)/e); sab (b/e)-((a-1)/e) (b/e) b e ((a-1)/e) (a-1) a 1 e long diff=b-a+1-sa-sb+sab; diff b-a+1-sa-sb+sab b-a+1-sa-sb b-a+1-sa-sb b-a+1 b-a b a 1 sa sb sab System.out.print(diff) System.out.print System.out System System.out diff String args[] args
import java.util.*;

class Main{
  
  	public static long gcd(long a,long b){
    	if(b==0)
          return a;
      	else
          return gcd(b,a%b);
    }
	public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
      long a=sc.nextLong();
      long b=sc.nextLong();
      long c=sc.nextLong();
      long d=sc.nextLong();
      
      long e=c*d/gcd(c,d);
      long sa=(b/c)-((a-1)/c);
      long sb=(b/d)-((a-1)/d);
      long sab=(b/e)-((a-1)/e);
      long diff=b-a+1-sa-sb+sab;
      System.out.print(diff);
      
    }
}