#include <bits/stdc++.h>
using namespace std;
long long exgcd(long long m, long long n, long long &x, long long &y) {
  int x1, y1, x0, y0;
  x0 = 1;
  y0 = 0;
  x1 = 0;
  y1 = 1;
  x = 0;
  y = 1;
  int r = m % n;
  int q = (m - r) / n;
  while (r) {
    x = x0 - q * x1;
    y = y0 - q * y1;
    x0 = x1;
    y0 = y1;
    x1 = x;
    y1 = y;
    m = n;
    n = r;
    r = m % n;
    q = (m - r) / n;
  }
  return n;
}
long long a1, b1, a2, b2, L, R;
long long abs1(long long x) {
  if (x > 0) return x;
  return -x;
}
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  L = max(b1, L);
  L = max(b2, L);
  if (L > R) {
    cout << 0 << endl;
    return 0;
  }
  long long x = 0, y = 0;
  long long d = exgcd(a1, a2, x, y);
  if ((b2 - b1) % d) {
    cout << 0 << endl;
    return 0;
  }
  x *= (b2 - b1) / d;
  x = (x % abs1(a2 / d) + abs1(a2 / d)) % abs1(a2 / d);
  long long lcm = a1 / d * a2;
  long long cnt = a1 * x + b1;
  long long ans = 0;
  if (cnt <= R) ans += (R - cnt) / lcm + 1;
  if (cnt < L) ans -= (L - 1 - cnt) / lcm + 1;
  cout << ans << endl;
  return 0;
}
