#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxn = 200010;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  } else {
    long long r = exgcd(b, a % b, x, y);
    long long t = x;
    x = y;
    y = t - (a / b) * y;
    return r;
  }
}
long long labs(long long a) {
  if (a < 0)
    return -a;
  else
    return a;
}
int main() {
  ios::sync_with_stdio(false);
  long long a1, a2, b1, b2, l, r;
  while (cin >> a1 >> b1 >> a2 >> b2 >> l >> r) {
    long long x, y;
    long long d = exgcd(a1, a2, x, y);
    if ((b2 - b1) % d) {
      puts("0");
      continue;
    }
    x *= (b2 - b1) / d;
    x = (x % labs(a2 / d) + labs(a2 / d)) % labs(a2 / d);
    long long cnt = x * a1 + b1;
    long long tmp = labs(a1 * a2 / d);
    long long ans = 0;
    l = max(l, max(b1, b2));
    if (l > r) {
      puts("0");
      continue;
    }
    if (cnt <= r) ans += (r - cnt) / tmp + 1;
    if (cnt < l) ans -= (l - 1 - cnt) / tmp + 1;
    printf("%I64d\n", ans);
  }
  return 0;
}
