#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double eps = 1e-10;
const double pi = acos(-1.0);
const long long INF = 1LL << 62;
const int inf = 1 << 29;
long long N, M, L, R, P;
long long xl[160001], xr[160001];
vector<long long> s[100001];
vector<long long> factor(long long n) {
  vector<long long> v;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) v.push_back(i);
    while (n % i == 0) n /= i;
  }
  if (n > 1) v.push_back(n);
  return v;
}
int main(void) {
  cin >> N >> M >> L >> R >> P;
  long long ans = 0;
  if (L == 1) ans += (N * (M + 1) + M * (N + 1)) % P;
  s[1].push_back(0);
  for (int i = 1; i <= N; i++) s[1].push_back((N + 1 - i) % P);
  for (int i = 2; i <= M; i++) {
    s[i].push_back(0);
    for (int j = 1; j * i <= N; j++)
      s[i].push_back((s[i].back() + s[1][j * i]) % P);
  }
  for (int i = 1; i <= N; i++) s[1][i] = (s[1][i] + s[1][i - 1]) % P;
  for (long long y = R - 1; y > 0; y--) {
    xl[y] = xl[y + 1];
    xr[y] = xr[y + 1];
    while (xl[y] * xl[y] + y * y < L * L) xl[y]++;
    while (xr[y] * xr[y] + y * y <= R * R) xr[y]++;
    xr[y]--;
  }
  for (int y = 1; y <= min(M, R); y++) {
    long long l = 0;
    if (xl[y] == 0) xl[y]++;
    if (xl[y] > N) continue;
    if (xr[y] > N) xr[y] = N;
    vector<long long> f = factor(y);
    for (int i = (0); i < (1 << f.size()); ++i) {
      long long k = 1;
      long long bit = (__builtin_popcount(i) & 1) ? -1 : 1;
      for (int j = (0); j < (f.size()); ++j)
        if (i & (1 << j)) k *= f[j];
      l += bit * (s[k][xr[y] / k] - s[k][(xl[y] - 1) / k]);
      l %= P;
      if (l < 0) l += P;
    }
    ans += (l * 2) % P * (M + 1 - y);
    ans %= P;
    if (ans < 0) ans += P;
  }
  cout << ans << endl;
  return 0;
}
