#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch & 15);
    ch = getchar();
  }
  if (f)
    return x;
  else
    return -x;
}
void exgcd(long long a, long long b, long long &d, long long &x, long long &y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
    return;
  }
  exgcd(b, a % b, d, y, x);
  y -= x * (a / b);
}
long long a1, b1, a2, b2, l, r, L, R;
long long A, B, C, g, x, y, ls, ans;
int main() {
  a1 = read(), b1 = read();
  a2 = read(), b2 = read();
  l = read(), r = read();
  A = a1, B = -a2, C = b2 - b1;
  exgcd(A, B, g, x, y);
  if (C % g) {
    puts("0");
    return 0;
  }
  x *= (C / g);
  ls = a2 / g;
  if (ls < 0) ls = -ls;
  x = (x % ls + ls) % ls;
  long long cnt = x * a1 + b1;
  ls = abs(a1 * a2 / g);
  l = max(l, max(b1, b2));
  if (l > r) {
    puts("0");
    return 0;
  }
  if (x * a1 + b1 <= r) ans += (r - (x * a1 + b1)) / ls + 1;
  if (x * a1 + b1 < l) ans -= (l - 1 - (x * a1 + b1)) / ls + 1;
  cout << ans << endl;
  return 0;
}
