#include <bits/stdc++.h>
using namespace std;
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  return in >> p.first >> p.second;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
  return _out(s, c.begin(), c.end());
}
__int128 invmod(__int128 a, __int128 b, __int128 s0 = 0, __int128 s1 = 1) {
  return b ? invmod(b, a % b, s1 - a / b * s0, s0) : s1;
}
__int128 gcd(__int128 a, __int128 b) { return b ? gcd(b, a % b) : a; }
signed main() {
  signed _a1, _b1, _a2, _b2, _L, _R;
  cin >> _a1 >> _b1 >> _a2 >> _b2 >> _L >> _R;
  __int128 a1 = _a1, b1 = _b1, a2 = _a2, b2 = _b2, L = _L, R = _R;
  if (b2 < b1) swap(a1, a2), swap(b1, b2);
  __int128 t1 = (invmod(a1, a2) % a2 + a2) % a2, g = gcd(a1, a2),
           t2 = (t1 * a1 - g) / a2;
  assert(t1 * a1 - t2 * a2 == g);
  if ((b2 - b1) % g) return cout << 0 << endl, 0;
  t1 *= (b2 - b1) / g, t2 *= (b2 - b1) / g;
  t1 = (t1 % (a2 / g) + a2 / g) % (a2 / g);
  t2 = (t2 % (a1 / g) + a1 / g) % (a1 / g);
  __int128 posa = max(t1 * a1 + b1, t2 * a2 + b2), add = a1 * a2 / g;
  L -= posa, R -= posa;
  L--;
  if (R < 0) return cout << 0 << endl, 0;
  if (L < 0) return cout << (int64_t)(R / add + 1) << endl, 0;
  cout << (int64_t)(R / add - L / add) << endl;
}
