import java.util.*;

public class Main{
  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();
    if (c<d){
      long g = c;
      c = d;
      d = g;
    }
    long gg = divisor(c,d);
    long e = c*d/gg;
    long f = find(a,b,c);
    long f1 = find(a,b,d);
    long f2 = find(a,b,e);
    System.out.println(b-a+1-f-f1+f2);
  }

  static long find(long a, long b, long c){
    long sum = 0;
    if (a%c == 0){
      sum += 1;
    }

    long aa = (long) a/c;
    long bb = (long) b/c;
    sum += (bb-aa);
    return sum;
  }

  static long divisor(long a, long b){
    if (b == 0){
      return a;
    }

    long remain = (long) a%b;
    a = b;
    b = remain;
    long result = divisor(a,b);
    return result;
  }
} import java.util.*; util.* java public class Main{
  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();
    if (c<d){
      long g = c;
      c = d;
      d = g;
    }
    long gg = divisor(c,d);
    long e = c*d/gg;
    long f = find(a,b,c);
    long f1 = find(a,b,d);
    long f2 = find(a,b,e);
    System.out.println(b-a+1-f-f1+f2);
  }

  static long find(long a, long b, long c){
    long sum = 0;
    if (a%c == 0){
      sum += 1;
    }

    long aa = (long) a/c;
    long bb = (long) b/c;
    sum += (bb-aa);
    return sum;
  }

  static long divisor(long a, long b){
    if (b == 0){
      return a;
    }

    long remain = (long) a%b;
    a = b;
    b = remain;
    long result = divisor(a,b);
    return result;
  }
} Main 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();
    if (c<d){
      long g = c;
      c = d;
      d = g;
    }
    long gg = divisor(c,d);
    long e = c*d/gg;
    long f = find(a,b,c);
    long f1 = find(a,b,d);
    long f2 = find(a,b,e);
    System.out.println(b-a+1-f-f1+f2);
  } main {
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = scan.nextLong();
    long c = scan.nextLong();
    long d = scan.nextLong();
    if (c<d){
      long g = c;
      c = d;
      d = g;
    }
    long gg = divisor(c,d);
    long e = c*d/gg;
    long f = find(a,b,c);
    long f1 = find(a,b,d);
    long f2 = find(a,b,e);
    System.out.println(b-a+1-f-f1+f2);
  } 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 if (c<d){
      long g = c;
      c = d;
      d = g;
    } c<d c d {
      long g = c;
      c = d;
      d = g;
    } long g = c; g c c = d c d d = g d g long gg = divisor(c,d); gg divisor(c,d) divisor c d long e = c*d/gg; e c*d/gg c*d c d gg long f = find(a,b,c); f find(a,b,c) find a b c long f1 = find(a,b,d); f1 find(a,b,d) find a b d long f2 = find(a,b,e); f2 find(a,b,e) find a b e System.out.println(b-a+1-f-f1+f2) System.out.println System.out System System.out b-a+1-f-f1+f2 b-a+1-f-f1 b-a+1-f-f1 b-a+1 b-a b a 1 f f1 f2 String[] args args static long find(long a, long b, long c){
    long sum = 0;
    if (a%c == 0){
      sum += 1;
    }

    long aa = (long) a/c;
    long bb = (long) b/c;
    sum += (bb-aa);
    return sum;
  } find {
    long sum = 0;
    if (a%c == 0){
      sum += 1;
    }

    long aa = (long) a/c;
    long bb = (long) b/c;
    sum += (bb-aa);
    return sum;
  } long sum = 0; sum 0 if (a%c == 0){
      sum += 1;
    } a%c == 0 a%c a c 0 {
      sum += 1;
    } sum += 1 sum 1 long aa = (long) a/c; aa (long) a/c (long) a c long bb = (long) b/c; bb (long) b/c (long) b c sum += (bb-aa) sum (bb-aa) bb aa return sum; sum long a a long b b long c c static long divisor(long a, long b){
    if (b == 0){
      return a;
    }

    long remain = (long) a%b;
    a = b;
    b = remain;
    long result = divisor(a,b);
    return result;
  } divisor {
    if (b == 0){
      return a;
    }

    long remain = (long) a%b;
    a = b;
    b = remain;
    long result = divisor(a,b);
    return result;
  } if (b == 0){
      return a;
    } b == 0 b 0 {
      return a;
    } return a; a long remain = (long) a%b; remain (long) a%b (long) a b a = b a b b = remain b remain long result = divisor(a,b); result divisor(a,b) divisor a b return result; result long a a long b b public class Main{
  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();
    if (c<d){
      long g = c;
      c = d;
      d = g;
    }
    long gg = divisor(c,d);
    long e = c*d/gg;
    long f = find(a,b,c);
    long f1 = find(a,b,d);
    long f2 = find(a,b,e);
    System.out.println(b-a+1-f-f1+f2);
  }

  static long find(long a, long b, long c){
    long sum = 0;
    if (a%c == 0){
      sum += 1;
    }

    long aa = (long) a/c;
    long bb = (long) b/c;
    sum += (bb-aa);
    return sum;
  }

  static long divisor(long a, long b){
    if (b == 0){
      return a;
    }

    long remain = (long) a%b;
    a = b;
    b = remain;
    long result = divisor(a,b);
    return result;
  }
} public class Main{
  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();
    if (c<d){
      long g = c;
      c = d;
      d = g;
    }
    long gg = divisor(c,d);
    long e = c*d/gg;
    long f = find(a,b,c);
    long f1 = find(a,b,d);
    long f2 = find(a,b,e);
    System.out.println(b-a+1-f-f1+f2);
  }

  static long find(long a, long b, long c){
    long sum = 0;
    if (a%c == 0){
      sum += 1;
    }

    long aa = (long) a/c;
    long bb = (long) b/c;
    sum += (bb-aa);
    return sum;
  }

  static long divisor(long a, long b){
    if (b == 0){
      return a;
    }

    long remain = (long) a%b;
    a = b;
    b = remain;
    long result = divisor(a,b);
    return result;
  }
} Main
import java.util.*;

public class Main{
  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();
    if (c<d){
      long g = c;
      c = d;
      d = g;
    }
    long gg = divisor(c,d);
    long e = c*d/gg;
    long f = find(a,b,c);
    long f1 = find(a,b,d);
    long f2 = find(a,b,e);
    System.out.println(b-a+1-f-f1+f2);
  }

  static long find(long a, long b, long c){
    long sum = 0;
    if (a%c == 0){
      sum += 1;
    }

    long aa = (long) a/c;
    long bb = (long) b/c;
    sum += (bb-aa);
    return sum;
  }

  static long divisor(long a, long b){
    if (b == 0){
      return a;
    }

    long remain = (long) a%b;
    a = b;
    b = remain;
    long result = divisor(a,b);
    return result;
  }
}
