#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 0x7FFFFFFF7FFFFFF;
ll _gcd(ll x, ll y, ll &ax, ll &by) {
  ll rem = x % y;
  ll d = x / y;
  if (rem == 0) {
    ax = 0;
    by = 1;
    return y;
  }
  if (y % rem == 0) {
    ax = 1;
    by = -d;
    return rem;
  }
  ll g = _gcd(y, x % y, ax, by);
  ll a = by;
  ll b = ax - d * by;
  ax = a;
  by = b;
  return g;
}
ll ceil(ll u, ll d) {
  ll ret = u / d;
  if (u > 0 and u % d != 0) ret++;
  return ret;
}
ll floor(ll u, ll d) {
  ll ret = u / d;
  if (u < 0 and u % d) ret--;
  return ret;
}
ll low(ll a, ll b, ll k0, ll k1, ll L) {
  L = ceil(L - b, a);
  L = ceil(L - k1, k0);
  return L;
}
ll hi(ll a, ll b, ll k0, ll k1, ll R) {
  R = floor(R - b, a);
  R = floor(R - k1, k0);
  return R;
}
int main() {
  ll a1, a2, b1, b2, c, L, R;
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  a2 = -a2;
  c = b2 - b1;
  ll k1, l1;
  ll g = _gcd(a1, a2, k1, l1);
  ll lcm = (a1 * a2) / g;
  ll d = c / g;
  k1 *= d;
  l1 *= d;
  if (c % g != 0) {
    cout << 0;
    return 0;
  }
  ll k0 = abs(lcm / a1);
  ll l0 = abs(lcm / a2);
  a2 = -a2;
  ll lower, upper;
  lower = low(a1, b1, k0, k1, L);
  lower = max(lower, low(a2, b2, l0, l1, L));
  upper = hi(a1, b1, k0, k1, R);
  upper = min(upper, hi(a2, b2, l0, l1, R));
  lower = max(lower, ceil(-k1, k0));
  lower = max(lower, ceil(-l1, l0));
  cout << max(upper - lower + 1, 0LL) << endl;
}
