#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 100001;
const int kMaxM = 100001;
const double EPS = 1e-8;
int n, m, l, r, Mod;
int sumx[kMaxN], sumy[kMaxM];
vector<pair<int, int> > sum[400];
void init() {
  cin >> n >> m;
  cin >> l >> r >> Mod;
  for (int i = 0; i <= n; i++) sumx[i] = n - i + 1;
  for (int i = 0; i <= m; i++) sumy[i] = m - i + 1;
  for (int i = 1; i * i <= m; i++)
    for (int j = i, s = 0; j <= m; j += i) {
      s = (s + sumy[j]) % Mod;
      sum[i].push_back(make_pair(j, s));
    }
  int t = 0;
  for (int i = 1; i * i <= m; i++) t += sum[i].size();
}
vector<int> factorize(int n) {
  vector<int> factor;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      factor.push_back(i);
      while (n % i == 0) n /= i;
    }
  if (n > 1) factor.push_back(n);
  return factor;
}
int mysqrt(long long x) { return sqrt(x) + EPS; }
long long sqr(int x) { return 1LL * x * x; }
int gcd(int x, int y) {
  if (!y) return x;
  return gcd(y, x % y);
}
int getLowerbound(long long val, vector<pair<int, int> > &v) {
  int l = 0, r = v.size() - 1, ret = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (sqr(v[mid].first) <= val) {
      ret = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  if (ret == -1) return 0;
  return v[ret].second;
}
long long calc2(int x, long long upper) {
  if (upper < 0) return 0;
  if (x == 0 && upper > 0) return sumy[1];
  long long ret = 0;
  if (x == 1) ret = sumy[0];
  if (upper == 0) return ret;
  vector<int> factor = factorize(x);
  upper = min(upper, 1LL * m * m);
  for (int i = 0; i < 1 << factor.size(); i++) {
    int val = 1, tot = 0;
    for (int j = 0; j < factor.size(); j++)
      if (i & (1 << j)) {
        val *= factor[j];
        tot++;
      }
    if (tot % 2) {
      tot = -1;
    } else {
      tot = 1;
    }
    long long s = 0;
    if (1LL * val * val > m) {
      for (int j = val; sqr(j) <= upper; j += val) s += sumy[j];
    } else {
      s = getLowerbound(upper, sum[val]);
    }
    ret += s * tot * 2;
  }
  return ret % Mod;
}
int calc(int x, int l, int r) {
  long long ret = calc2(x, sqr(r) - sqr(x)) - calc2(x, sqr(l) - sqr(x) - 1);
  ret = (ret % Mod + Mod) % Mod;
  return ret;
}
void solve() {
  long long ret = 0;
  for (int x = 0; x <= r && x <= n; x++) {
    ret = (ret + 1LL * sumx[x] * calc(x, l, r)) % Mod;
  }
  ret %= Mod;
  cout << ret << endl;
}
int main() {
  init();
  solve();
  return 0;
}
