#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, a, b, c, g, L, R, x, y, m, M, ans, tot;
void exgcd(long long a, long long b, long long &g, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    g = a;
    return;
  }
  exgcd(b, a % b, g, x, y);
  long long t = x;
  x = y;
  y = t - a / b * y;
}
int main() {
  scanf("%lld%lld%lld%lld%lld%lld", &a1, &b1, &a2, &b2, &L, &R);
  c = b2 - b1;
  exgcd(a1, a2, g, x, y);
  if (c % g) {
    printf("0");
    return 0;
  }
  long long t = c / g;
  y = -y;
  x *= t;
  y *= t;
  m = a2 / g;
  M = a1 / g * a2;
  x = (x % m + m) % m;
  if (max(b1, b2) > R)
    printf("0");
  else {
    L = max(L, max(b1, b2));
    tot = a1 * x + b1;
    if (tot <= R) ans += (R - tot) / M + 1;
    if (tot < L) ans -= (L - tot - 1) / M + 1;
    printf("%lld", ans);
  }
  return 0;
}
