#include <bits/stdc++.h>
const int N = 1e5 + 5;
const int M = 1e3 + 10;
const int mod = 9973;
using namespace std;
long long m, n, x, y, l, r, t, a1, r1, a2, r2;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void e_gcd(long long a, long long b, long long &g, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0, g = a;
    return;
  } else {
    e_gcd(b, a % b, g, y, x);
    y -= (a / b) * x;
  }
}
inline long long crt() {
  long long ans, sum = 0, g, x, y;
  e_gcd(a1, a2, g, x, y);
  if ((r2 - r1) % g != 0) return 0;
  t = (r2 - r1) / g;
  x *= t;
  t = a2 / g;
  x = (x % t + t) % t;
  ans = r1 + a1 * x;
  t = abs(a1 * a2 / g);
  l = max(l, max(r1, r2));
  if (l > r) return 0;
  if (ans <= r) sum += (r - ans) / t + 1;
  if (ans < l) sum -= (l - ans - 1) / t + 1;
  return sum;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a1, &r1, &a2, &r2, &l, &r);
  printf("%I64d\n", crt());
  return 0;
}
