#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long a1, a2, b1, b2, l, r, x, y;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long gcd = exgcd(b, a % b, x, y);
  long long tp = x;
  x = y;
  y = tp - a / b * y;
  return gcd;
}
long long mul(long long a, long long b, long long p) {
  a %= p, b %= p;
  long long c = (long long)a * b / p;
  long long ans = a * b - c * p;
  if (ans < 0)
    ans += p;
  else if (ans >= p)
    ans -= p;
  return ans;
}
int main() {
  while (~scanf("%lld%lld%lld%lld%lld%lld", &a1, &b1, &a2, &b2, &l, &r)) {
    long long c = b2 - b1;
    long long d = exgcd(a1, a2, x, y);
    if (r < b1 || r < b2) {
      cout << "0" << endl;
      return 0;
    }
    l = max(max(b1, b2), l);
    if (c % d != 0) {
      cout << "0" << endl;
      return 0;
    } else {
      long long k = c / d;
      x = x * k;
      long long bg = a2 / d;
      long long z = (long long)ceil((double)(l - b1) / a1);
      long long y = (long long)floor((double)(r - b1) / a1);
      long long zz = (long long)ceil((double)(z - x) / bg);
      long long yy = (long long)floor((double)(y - x) / bg);
      long long ans = yy - zz + 1;
      cout << ans << endl;
    }
  }
  return 0;
}
