#include <bits/stdc++.h>
const double PI = 3.1415926535897932384626433832795028841971;
const long long int INF = 5 * (1e9);
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
long long a1, a2, b1, b2, l, r;
long long ans = 0;
long long g = 1;
void func() {
  long long x = a1, y = a2;
  while (y) {
    x %= y;
    swap(x, y);
  }
  g = x;
}
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  if (a2 > a1) {
    swap(a1, a2);
    swap(b1, b2);
  }
  if (a1 >= 1000) {
    for (long long i = 0;; i++) {
      if (a1 * i + b1 > r) break;
      if (a1 * i + b1 < l) continue;
      if (a1 * i + b1 - b2 >= 0 && (a1 * i + b1 - b2) % a2 == 0) ans++;
    }
    cout << ans << endl;
    return 0;
  }
  func();
  if (abs(b1 - b2) % g != 0) {
    cout << 0 << endl;
    return 0;
  }
  long long st = 0;
  for (long long i = 0; i <= a2; i++) {
    if ((a1 * i + b1 - b2) % a2 == 0) {
      st = a1 * i + b1;
      break;
    }
  }
  long long v = a1 * a2 / g;
  if (st - b2 < 0) {
    long long s = 0, e = INF, mid;
    while (e - s > 1) {
      mid = (s + e) / 2;
      if (st + v * mid < b2)
        s = mid;
      else
        e = mid;
    }
    st += v * e;
  }
  if (st > r) {
    cout << 0 << endl;
    return 0;
  }
  long long ss, ee;
  long long s = 0, e = INF, mid;
  while (e - s > 1) {
    mid = (s + e) / 2;
    if (v * mid + st < l)
      s = mid;
    else
      e = mid;
  }
  if (st < l)
    ss = e;
  else
    ss = e - 1;
  s = 0;
  e = INF;
  while (e - s > 1) {
    mid = (s + e) / 2;
    if (v * mid + st > r)
      e = mid;
    else
      s = mid;
  }
  ee = s;
  cout << ee - ss + 1 << endl;
}
