#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, L, R, k, l, kk, ll, l1, r1, l2, r2, x, gcd, lcm;
inline long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    return x = 1, y = 0, a;
  }
  long long t = exgcd(b, a % b, y, x);
  return y -= a / b * x, t;
}
int main() {
  scanf("%lld%lld%lld%lld%lld%lld", &a, &c, &b, &d, &L, &R);
  gcd = exgcd(a, b, k, l), lcm = a * b / gcd;
  if ((d - c) % gcd) return puts("0"), 0;
  k *= (d - c) / gcd, kk = lcm / a;
  l *= (c - d) / gcd, ll = lcm / b;
  l1 = max(0ll, (L - c) / a + (L - c > 0 ? (!!((L - c) % a)) : 0));
  r1 = (R - c) / a - (R - c < 0 ? (!!((R - c) % a)) : 0);
  l2 = max(0ll, (L - d) / b + (L - d > 0 ? (!!((L - d) % b)) : 0));
  r2 = (R - d) / b - (R - d < 0 ? (!!((R - d) % b)) : 0);
  x = max((l1 - k) / kk, (l2 - l) / ll);
  k += x * kk, l += x * ll;
  if (k < l1 || l < l2) k += kk, l += ll;
  if (k > r1 || l > r2) return puts("0"), 0;
  printf("%lld\n", min((r1 - k) / kk, (r2 - l) / ll) + 1);
  return 0;
}
