import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
    long g;
    if(c>=d){
      g = gcd(c,d);
    }else{
      g = gcd(d,c);
    }
    long l = (c/g)*(d/g)*g;
    long cnt1 = b/c-(a+c-1)/c;
    long cnt2 = b/d-(a+d-1)/d;
    long cnt3 = b/l-(a+l-1)/l;
    if(cnt1<0){
      cnt1 = 0;
    }else{
      cnt1++;
    }
    if(cnt2<0){
      cnt2 = 0;
    }else{
      cnt2++;
    }
    if(cnt3<0){
      cnt3 = 0;
    }else{
      cnt3++;
    }
    
    System.out.println(b-a+1-(cnt1+cnt2-cnt3));
    System.out.flush();
  }
  
  public static long gcd(long a,long b){
    if(b==0){
      return a;
    }else{
      return gcd(b,a%b);
    }
  }
} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
    long g;
    if(c>=d){
      g = gcd(c,d);
    }else{
      g = gcd(d,c);
    }
    long l = (c/g)*(d/g)*g;
    long cnt1 = b/c-(a+c-1)/c;
    long cnt2 = b/d-(a+d-1)/d;
    long cnt3 = b/l-(a+l-1)/l;
    if(cnt1<0){
      cnt1 = 0;
    }else{
      cnt1++;
    }
    if(cnt2<0){
      cnt2 = 0;
    }else{
      cnt2++;
    }
    if(cnt3<0){
      cnt3 = 0;
    }else{
      cnt3++;
    }
    
    System.out.println(b-a+1-(cnt1+cnt2-cnt3));
    System.out.flush();
  }
  
  public static long gcd(long a,long b){
    if(b==0){
      return a;
    }else{
      return gcd(b,a%b);
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
    long g;
    if(c>=d){
      g = gcd(c,d);
    }else{
      g = gcd(d,c);
    }
    long l = (c/g)*(d/g)*g;
    long cnt1 = b/c-(a+c-1)/c;
    long cnt2 = b/d-(a+d-1)/d;
    long cnt3 = b/l-(a+l-1)/l;
    if(cnt1<0){
      cnt1 = 0;
    }else{
      cnt1++;
    }
    if(cnt2<0){
      cnt2 = 0;
    }else{
      cnt2++;
    }
    if(cnt3<0){
      cnt3 = 0;
    }else{
      cnt3++;
    }
    
    System.out.println(b-a+1-(cnt1+cnt2-cnt3));
    System.out.flush();
  } main {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
    long g;
    if(c>=d){
      g = gcd(c,d);
    }else{
      g = gcd(d,c);
    }
    long l = (c/g)*(d/g)*g;
    long cnt1 = b/c-(a+c-1)/c;
    long cnt2 = b/d-(a+d-1)/d;
    long cnt3 = b/l-(a+l-1)/l;
    if(cnt1<0){
      cnt1 = 0;
    }else{
      cnt1++;
    }
    if(cnt2<0){
      cnt2 = 0;
    }else{
      cnt2++;
    }
    if(cnt3<0){
      cnt3 = 0;
    }else{
      cnt3++;
    }
    
    System.out.println(b-a+1-(cnt1+cnt2-cnt3));
    System.out.flush();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c = Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d = Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long g; g if(c>=d){
      g = gcd(c,d);
    }else{
      g = gcd(d,c);
    } c>=d c d {
      g = gcd(c,d);
    } g = gcd(c,d) g gcd(c,d) gcd c d {
      g = gcd(d,c);
    } g = gcd(d,c) g gcd(d,c) gcd d c long l = (c/g)*(d/g)*g; l (c/g)*(d/g)*g (c/g)*(d/g)*g (c/g) c g (d/g) d g g long cnt1 = b/c-(a+c-1)/c; cnt1 b/c-(a+c-1)/c b/c b c (a+c-1)/c (a+c-1) a+c a c 1 c long cnt2 = b/d-(a+d-1)/d; cnt2 b/d-(a+d-1)/d b/d b d (a+d-1)/d (a+d-1) a+d a d 1 d long cnt3 = b/l-(a+l-1)/l; cnt3 b/l-(a+l-1)/l b/l b l (a+l-1)/l (a+l-1) a+l a l 1 l if(cnt1<0){
      cnt1 = 0;
    }else{
      cnt1++;
    } cnt1<0 cnt1 0 {
      cnt1 = 0;
    } cnt1 = 0 cnt1 0 {
      cnt1++;
    } cnt1++ cnt1 if(cnt2<0){
      cnt2 = 0;
    }else{
      cnt2++;
    } cnt2<0 cnt2 0 {
      cnt2 = 0;
    } cnt2 = 0 cnt2 0 {
      cnt2++;
    } cnt2++ cnt2 if(cnt3<0){
      cnt3 = 0;
    }else{
      cnt3++;
    } cnt3<0 cnt3 0 {
      cnt3 = 0;
    } cnt3 = 0 cnt3 0 {
      cnt3++;
    } cnt3++ cnt3 System.out.println(b-a+1-(cnt1+cnt2-cnt3)) System.out.println System.out System System.out b-a+1-(cnt1+cnt2-cnt3) b-a+1 b-a b a 1 (cnt1+cnt2-cnt3) cnt1+cnt2 cnt1 cnt2 cnt3 System.out.flush() System.out.flush System.out System System.out String[] args args 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;
    } return a; a {
      return gcd(b,a%b);
    } return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
    long g;
    if(c>=d){
      g = gcd(c,d);
    }else{
      g = gcd(d,c);
    }
    long l = (c/g)*(d/g)*g;
    long cnt1 = b/c-(a+c-1)/c;
    long cnt2 = b/d-(a+d-1)/d;
    long cnt3 = b/l-(a+l-1)/l;
    if(cnt1<0){
      cnt1 = 0;
    }else{
      cnt1++;
    }
    if(cnt2<0){
      cnt2 = 0;
    }else{
      cnt2++;
    }
    if(cnt3<0){
      cnt3 = 0;
    }else{
      cnt3++;
    }
    
    System.out.println(b-a+1-(cnt1+cnt2-cnt3));
    System.out.flush();
  }
  
  public static long gcd(long a,long b){
    if(b==0){
      return a;
    }else{
      return gcd(b,a%b);
    }
  }
}