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();

    sc.close();

    long lcm_ = lcm(C, D);

    long A1 = A / C;
    long B1 = B / C;
    long AB1 = B1 - A1;
    if (A % C == 0) {
      AB1++;
    }

    long A2 = A / D;
    long B2 = B / D;
    long AB2 = B2 - A2;
    if (A % D == 0) {
      AB2++;
    }

    long A3 = A / lcm_;
    long B3 = B / lcm_;
    long AB3 = B3 - A3;
    if (A % lcm_ == 0) {
      AB3++;
    }

    long AB = AB1 + AB2 - AB3;

    System.out.println(B - A + 1 - AB);

  }

  public static long gcd(long x, long y){

    if (y == 0) {
      return x;
    }
    
    return gcd(y, x % y);
    
  }

  public static long lcm(long x, long y) {

		return x / gcd(x, y) * y;
  
  }

} 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();

    sc.close();

    long lcm_ = lcm(C, D);

    long A1 = A / C;
    long B1 = B / C;
    long AB1 = B1 - A1;
    if (A % C == 0) {
      AB1++;
    }

    long A2 = A / D;
    long B2 = B / D;
    long AB2 = B2 - A2;
    if (A % D == 0) {
      AB2++;
    }

    long A3 = A / lcm_;
    long B3 = B / lcm_;
    long AB3 = B3 - A3;
    if (A % lcm_ == 0) {
      AB3++;
    }

    long AB = AB1 + AB2 - AB3;

    System.out.println(B - A + 1 - AB);

  }

  public static long gcd(long x, long y){

    if (y == 0) {
      return x;
    }
    
    return gcd(y, x % y);
    
  }

  public static long lcm(long x, long y) {

		return x / gcd(x, y) * y;
  
  }

} 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();

    sc.close();

    long lcm_ = lcm(C, D);

    long A1 = A / C;
    long B1 = B / C;
    long AB1 = B1 - A1;
    if (A % C == 0) {
      AB1++;
    }

    long A2 = A / D;
    long B2 = B / D;
    long AB2 = B2 - A2;
    if (A % D == 0) {
      AB2++;
    }

    long A3 = A / lcm_;
    long B3 = B / lcm_;
    long AB3 = B3 - A3;
    if (A % lcm_ == 0) {
      AB3++;
    }

    long AB = AB1 + AB2 - AB3;

    System.out.println(B - A + 1 - AB);

  } main {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long lcm_ = lcm(C, D);

    long A1 = A / C;
    long B1 = B / C;
    long AB1 = B1 - A1;
    if (A % C == 0) {
      AB1++;
    }

    long A2 = A / D;
    long B2 = B / D;
    long AB2 = B2 - A2;
    if (A % D == 0) {
      AB2++;
    }

    long A3 = A / lcm_;
    long B3 = B / lcm_;
    long AB3 = B3 - A3;
    if (A % lcm_ == 0) {
      AB3++;
    }

    long AB = AB1 + AB2 - AB3;

    System.out.println(B - A + 1 - AB);

  } 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 sc.close() sc.close sc long lcm_ = lcm(C, D); lcm_ lcm(C, D) lcm C D long A1 = A / C; A1 A / C A C long B1 = B / C; B1 B / C B C long AB1 = B1 - A1; AB1 B1 - A1 B1 A1 if (A % C == 0) {
      AB1++;
    } A % C == 0 A % C A C 0 {
      AB1++;
    } AB1++ AB1 long A2 = A / D; A2 A / D A D long B2 = B / D; B2 B / D B D long AB2 = B2 - A2; AB2 B2 - A2 B2 A2 if (A % D == 0) {
      AB2++;
    } A % D == 0 A % D A D 0 {
      AB2++;
    } AB2++ AB2 long A3 = A / lcm_; A3 A / lcm_ A lcm_ long B3 = B / lcm_; B3 B / lcm_ B lcm_ long AB3 = B3 - A3; AB3 B3 - A3 B3 A3 if (A % lcm_ == 0) {
      AB3++;
    } A % lcm_ == 0 A % lcm_ A lcm_ 0 {
      AB3++;
    } AB3++ AB3 long AB = AB1 + AB2 - AB3; AB AB1 + AB2 - AB3 AB1 + AB2 AB1 AB2 AB3 System.out.println(B - A + 1 - AB) System.out.println System.out System System.out B - A + 1 - AB B - A + 1 B - A B A 1 AB String[] args args public static long gcd(long x, long y){

    if (y == 0) {
      return x;
    }
    
    return gcd(y, x % y);
    
  } gcd {

    if (y == 0) {
      return x;
    }
    
    return gcd(y, x % y);
    
  } if (y == 0) {
      return x;
    } y == 0 y 0 {
      return x;
    } return x; x return gcd(y, x % y); gcd(y, x % y) gcd y x % y x y long x x long y y public static long lcm(long x, long y) {

		return x / gcd(x, y) * y;
  
  } lcm {

		return x / gcd(x, y) * y;
  
  } return x / gcd(x, y) * y; x / gcd(x, y) * y x / gcd(x, y) x gcd(x, y) gcd x y y long x x long y y 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();

    sc.close();

    long lcm_ = lcm(C, D);

    long A1 = A / C;
    long B1 = B / C;
    long AB1 = B1 - A1;
    if (A % C == 0) {
      AB1++;
    }

    long A2 = A / D;
    long B2 = B / D;
    long AB2 = B2 - A2;
    if (A % D == 0) {
      AB2++;
    }

    long A3 = A / lcm_;
    long B3 = B / lcm_;
    long AB3 = B3 - A3;
    if (A % lcm_ == 0) {
      AB3++;
    }

    long AB = AB1 + AB2 - AB3;

    System.out.println(B - A + 1 - AB);

  }

  public static long gcd(long x, long y){

    if (y == 0) {
      return x;
    }
    
    return gcd(y, x % y);
    
  }

  public static long lcm(long x, long y) {

		return x / gcd(x, y) * y;
  
  }

} 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();

    sc.close();

    long lcm_ = lcm(C, D);

    long A1 = A / C;
    long B1 = B / C;
    long AB1 = B1 - A1;
    if (A % C == 0) {
      AB1++;
    }

    long A2 = A / D;
    long B2 = B / D;
    long AB2 = B2 - A2;
    if (A % D == 0) {
      AB2++;
    }

    long A3 = A / lcm_;
    long B3 = B / lcm_;
    long AB3 = B3 - A3;
    if (A % lcm_ == 0) {
      AB3++;
    }

    long AB = AB1 + AB2 - AB3;

    System.out.println(B - A + 1 - AB);

  }

  public static long gcd(long x, long y){

    if (y == 0) {
      return x;
    }
    
    return gcd(y, x % y);
    
  }

  public static long lcm(long x, long y) {

		return x / gcd(x, y) * y;
  
  }

} 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();

    sc.close();

    long lcm_ = lcm(C, D);

    long A1 = A / C;
    long B1 = B / C;
    long AB1 = B1 - A1;
    if (A % C == 0) {
      AB1++;
    }

    long A2 = A / D;
    long B2 = B / D;
    long AB2 = B2 - A2;
    if (A % D == 0) {
      AB2++;
    }

    long A3 = A / lcm_;
    long B3 = B / lcm_;
    long AB3 = B3 - A3;
    if (A % lcm_ == 0) {
      AB3++;
    }

    long AB = AB1 + AB2 - AB3;

    System.out.println(B - A + 1 - AB);

  }

  public static long gcd(long x, long y){

    if (y == 0) {
      return x;
    }
    
    return gcd(y, x % y);
    
  }

  public static long lcm(long x, long y) {

		return x / gcd(x, y) * y;
  
  }

}