#include <bits/stdc++.h>
namespace codeforces {
int main();
}
int main() { return codeforces::main(); }
namespace codeforces {
using namespace std;
using int64 = long long int;
int ReadInt() {
  int value;
  fscanf(stdin, "%d", &value);
  return value;
}
void gcd(int64 u, int64 v, int64* g, int64* x, int64* y) {
  int64 x1 = 1;
  int64 y1 = 0;
  int64 x2 = 0;
  int64 y2 = 1;
  while (v > 0) {
    const int64 q = u / v;
    const int64 r = u - q * v;
    const int64 x3 = x1 - q * x2;
    const int64 y3 = y1 - q * y2;
    x1 = x2;
    x2 = x3;
    y1 = y2;
    y2 = y3;
    u = v;
    v = r;
  }
  *g = u;
  *x = x1;
  *y = y1;
}
void intersect(int64 a1, int64 b1, int64 a2, int64 b2, int64* a, int64* b) {
  int64 g, x, y;
  gcd(a1, a2, &g, &x, &y);
  if ((b1 - b2) % g != 0) {
    *a = *b = 0;
    return;
  }
  const int64 z = b1 % g;
  const int64 modulo = a1 * (a2 / g);
  const int64 left = a1 * ((((b2 - z) / g) * x) % a2);
  const int64 right = a2 * ((((b1 - z) / g) * y) % a1);
  int64 t = (z + left + right) % modulo;
  t = (t + modulo) % modulo;
  const int64 bound1 =
      (b1 >= t) ? (b1 - t + modulo - 1) / modulo : (b1 - t) / modulo;
  const int64 bound2 =
      (b2 >= t) ? (b2 - t + modulo - 1) / modulo : (b2 - t) / modulo;
  *a = modulo;
  *b = t + max(bound1, bound2) * modulo;
}
int main() {
  const int64 a1 = ReadInt();
  const int64 b1 = ReadInt();
  const int64 a2 = ReadInt();
  const int64 b2 = ReadInt();
  const int64 l = ReadInt();
  const int64 r = ReadInt();
  int64 a, b;
  intersect(a1, b1, a2, b2, &a, &b);
  if (a == 0 || r < b) {
    cout << "0\n";
    return 0;
  }
  const int64 lower = (max<int64>(l - b, 0) + a - 1) / a;
  const int64 upper = (r - b) / a;
  if (lower > upper) {
    cout << "0\n";
    return 0;
  }
  cout << (upper - lower + 1) << "\n";
  return 0;
}
}  // namespace codeforces
