#include <bits/stdc++.h>
using namespace std;
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
  scanf("%d", &head);
  RI(tail...);
}
vector<int> fac[150010];
int cnt[150010];
void predo() {
  for (int i = 2; i < 150010; i++)
    for (int j = i; j < 150010; j += i) fac[j].push_back(i);
  for (int i = 2; i < 150010; i++)
    if (((int)(fac[i]).size()) == 1)
      for (int j = i; j < 150010; j += i) cnt[j]++;
  for (int i = 2; i < 150010; i++) cnt[i] = (cnt[i] % 2 == 1 ? -1 : +1);
  for (int i = 2; i * i < 150010; i++)
    if (((int)(fac[i]).size()) == 1)
      for (int j = i * i; j < 150010; j += i * i) cnt[j] = 0;
}
long long p;
long long shik(long long l, long long r) {
  return (r + l) * (r - l + 1) / 2 % p;
}
long long shik(long long l, long long r, long long d) {
  return (r + l) * ((r - l) / d + 1) / 2 % p;
}
int main() {
  predo();
  long long n, m, l, r;
  cin >> n >> m >> l >> r >> p;
  long long ans = 0;
  for (long long dx = 1; dx <= n && dx * dx <= r * r; dx++) {
    long long ly = dx >= l ? 0 : sqrt(l * l - dx * dx);
    long long ry = sqrt(r * r - dx * dx);
    while (ly == 0 || dx * dx + ly * ly < l * l) ly++;
    while (dx * dx + ry * ry > r * r) ry--;
    if (ry > m) ry = m;
    if (ly > ry) continue;
    ans += (n + 1 - dx) * shik(m + 1 - ry, m + 1 - ly) % p;
    for (auto f : fac[dx]) {
      long long lly = (ly + f - 1) / f;
      long long rry = ry / f;
      if (lly > rry) continue;
      long long now =
          cnt[f] * (n + 1 - dx) * shik(m + 1 - f * rry, m + 1 - f * lly, f) % p;
      ans += now;
    }
  }
  ans *= 2;
  if (l == 1) {
    ans += (n + 1) * m % p;
    ans += n * (m + 1) % p;
  }
  ans %= p;
  if (ans < 0) ans += p;
  cout << ans << endl;
  return 0;
}
