#include <bits/stdc++.h>
using namespace std;
namespace diophantine {
long long ex_gcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = ex_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
bool get_one_solution(long long a, long long b, long long c, long long &x0,
                      long long &y0, long long &g) {
  g = ex_gcd(abs(a), abs(b), x0, y0);
  if (c % g) return false;
  x0 *= c / g;
  y0 *= c / g;
  if (a < 0) x0 = -x0;
  if (b < 0) y0 = -y0;
  return true;
}
}  // namespace diophantine
bool check(long long a1, long long b1, long long x1, long long d1, long long lb,
           long long ub, long long &t1, long long &p1) {
  if (d1 == 0) {
    long long c = x1 * a1 + b1;
    if (c < lb || c > ub) {
      return false;
    }
  } else {
    if (b1 >= lb)
      t1 = -((b1 - lb) / a1);
    else
      t1 = (lb - b1 + a1 - 1) / a1;
    if (b1 <= ub)
      p1 = (ub - b1) / a1;
    else
      p1 = -((b1 - ub + a1 - 1) / a1);
    t1 = max(t1, 0LL);
    if (t1 > p1) return false;
    if (t1 > x1)
      t1 = (t1 - x1 + abs(d1) - 1) / abs(d1);
    else
      t1 = -((x1 - t1) / abs(d1));
    if (p1 >= x1)
      p1 = (p1 - x1) / abs(d1);
    else
      p1 = -((x1 - p1 + abs(d1) - 1) / abs(d1));
    if (d1 < 0) {
      t1 = -t1;
      p1 = -p1;
      swap(t1, p1);
    }
    if (t1 > p1) return false;
  }
  return true;
}
int main() {
  long long a1, b1, a2, b2, l, r;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long x1, x2, g;
  if (!diophantine::get_one_solution(a1, -a2, b2 - b1, x1, x2, g)) {
    printf("0");
    return 0;
  }
  long long d1 = -a2 / g;
  long long d2 = -a1 / g;
  long long t1, p1, t2, p2;
  if (!check(a1, b1, x1, d1, l, r, t1, p1) ||
      !check(a2, b2, x2, d2, l, r, t2, p2)) {
    printf("0");
    return 0;
  }
  long long ans = 0;
  if (t1 <= p2 && t2 <= p1) ans = min(p1, p2) - max(t1, t2) + 1;
  cout << ans;
  return 0;
}
