#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
long long mod;
vector<long long> fact(long long x) {
  vector<long long> res;
  for (long long d = 2; x > 1; ++d) {
    if (d * d > x) d = x;
    if (x % d == 0) {
      res.push_back(d);
      while (x % d == 0) x /= d;
    }
  }
  return res;
}
pair<long long, long long> f(long long a, long long n) {
  if (n < 1) return make_pair(0ll, 0ll);
  vector<long long> p = fact(a);
  int m = p.size();
  long long res = 0;
  long long res2 = 0;
  for (int ms = 0; ms < (1 << m); ++ms) {
    long long x = 1, z = 1;
    for (int i = 0; i < m; ++i)
      if (ms >> i & 1) x *= p[i], z = -z;
    long long c = n / x;
    res += (c * c + c) / 2 * x * z;
    res2 += c * z;
  }
  return make_pair(res, res2);
}
int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }
long long br(int n, int m, int L, int R) {
  int ans = 0;
  for (int ax = 0; ax <= n; ++ax)
    for (int ay = 0; ay <= m; ++ay)
      for (int bx = 0; bx <= n; ++bx)
        for (int by = 0; by <= m; ++by)
          if (ax != bx || ay != by) {
            int d = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
            if (L * L <= d && d <= R * R &&
                gcd(abs(ax - bx), abs(ay - by)) == 1)
              ++ans;
          }
  return ans / 2 % mod;
}
int main() {
  long long n, m, L, R;
  cin >> n >> m >> L >> R >> mod;
  long long ans = L < 2 ? (m + 1) * n + (n + 1) * m : 0;
  ans %= mod;
  long long l = n, r = n;
  for (long long a = 1; a <= m && a < R; ++a) {
    while (l > 0 && (l - 1) * (l - 1) + a * a >= L * L) --l;
    while (r * r + a * a > R * R) --r;
    if (!(L * L <= l * l + a * a && l <= r && r * r + a * a <= R * R)) continue;
    pair<long long, long long> pp1 = f(a, r);
    pair<long long, long long> pp2 = f(a, l - 1);
    long long sb = pp1.first - pp2.first;
    long long bn = pp1.second - pp2.second;
    sb = (sb + mod) % mod;
    bn = (bn + mod) % mod;
    long long res = -sb * (m - a + 1) + (n + 1) * (m - a + 1) * bn;
    res = (res % mod + mod) % mod;
    ans += res * 2;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
