#include <bits/stdc++.h>
using namespace std;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long long ans = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return ans;
}
int main() {
  long long a1, b1, a2, b2, l, r, xx, yy;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long d = exgcd(a1, a2, xx, yy);
  if ((b2 - b1) % d) {
    cout << 0 << endl;
    return 0;
  }
  long long x = a2 / d;
  xx = (b2 - b1) / d * xx;
  xx = (xx % x + x) % x;
  l = max(l, max(b1, b2));
  long long ans = 0, cnt = a1 * xx + b1, lcm = a1 / d * a2;
  if (l > r) {
    cout << 0 << endl;
    return 0;
  }
  if (cnt <= r) ans += (r - cnt) / lcm + 1;
  if (cnt < l) ans -= (l - cnt - 1) / lcm + 1;
  cout << ans << endl;
  return 0;
}
