import java.util.*;
public class Main{
  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 cab=b/c-(a-1)/c;
    long dab=b/d-(a-1)/d;
    long e=c*d/gcm(c,d);
    long i=1;
    long eab=b/e-(a-1)/e;
    System.out.println( b-(a-1) - cab - dab + eab );
  }
  static long gcm(long cc,long dd){
    long c=cc;
    long d=dd;
    while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    }
  }
} import java.util.*; util.* java public class Main{
  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 cab=b/c-(a-1)/c;
    long dab=b/d-(a-1)/d;
    long e=c*d/gcm(c,d);
    long i=1;
    long eab=b/e-(a-1)/e;
    System.out.println( b-(a-1) - cab - dab + eab );
  }
  static long gcm(long cc,long dd){
    long c=cc;
    long d=dd;
    while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    }
  }
} Main 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 cab=b/c-(a-1)/c;
    long dab=b/d-(a-1)/d;
    long e=c*d/gcm(c,d);
    long i=1;
    long eab=b/e-(a-1)/e;
    System.out.println( b-(a-1) - cab - dab + eab );
  } main {
    Scanner sc = new Scanner(System.in);
    long a=sc.nextLong();
    long b=sc.nextLong();
    long c=sc.nextLong();
    long d=sc.nextLong();
    long cab=b/c-(a-1)/c;
    long dab=b/d-(a-1)/d;
    long e=c*d/gcm(c,d);
    long i=1;
    long eab=b/e-(a-1)/e;
    System.out.println( b-(a-1) - cab - dab + eab );
  } 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 cab=b/c-(a-1)/c; cab b/c-(a-1)/c b/c b c (a-1)/c (a-1) a 1 c long dab=b/d-(a-1)/d; dab b/d-(a-1)/d b/d b d (a-1)/d (a-1) a 1 d long e=c*d/gcm(c,d); e c*d/gcm(c,d) c*d c d gcm(c,d) gcm c d long i=1; i 1 long eab=b/e-(a-1)/e; eab b/e-(a-1)/e b/e b e (a-1)/e (a-1) a 1 e System.out.println( b-(a-1) - cab - dab + eab ) System.out.println System.out System System.out b-(a-1) - cab - dab + eab b-(a-1) - cab - dab cab b-(a-1) - cab - dab b (a-1) a 1 cab dab eab String[] args args static long gcm(long cc,long dd){
    long c=cc;
    long d=dd;
    while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    }
  } gcm {
    long c=cc;
    long d=dd;
    while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    }
  } long c=cc; c cc long d=dd; d dd while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    } true {
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    } long f=c%d; f c%d c d if(f==0){
        return d;
      } f==0 f 0 {
        return d;
      } return d; d c=d c d d=f d f long cc cc long dd dd public class Main{
  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 cab=b/c-(a-1)/c;
    long dab=b/d-(a-1)/d;
    long e=c*d/gcm(c,d);
    long i=1;
    long eab=b/e-(a-1)/e;
    System.out.println( b-(a-1) - cab - dab + eab );
  }
  static long gcm(long cc,long dd){
    long c=cc;
    long d=dd;
    while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    }
  }
} public class Main{
  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 cab=b/c-(a-1)/c;
    long dab=b/d-(a-1)/d;
    long e=c*d/gcm(c,d);
    long i=1;
    long eab=b/e-(a-1)/e;
    System.out.println( b-(a-1) - cab - dab + eab );
  }
  static long gcm(long cc,long dd){
    long c=cc;
    long d=dd;
    while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    }
  }
} Main
import java.util.*;
public class Main{
  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 cab=b/c-(a-1)/c;
    long dab=b/d-(a-1)/d;
    long e=c*d/gcm(c,d);
    long i=1;
    long eab=b/e-(a-1)/e;
    System.out.println( b-(a-1) - cab - dab + eab );
  }
  static long gcm(long cc,long dd){
    long c=cc;
    long d=dd;
    while(true){
      long f=c%d;
      if(f==0){
        return d;
      }
      c=d;
      d=f;
    }
  }
}
