#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150100;
long long n, m, l, r;
long long P;
vector<int> p;
long long sum;
long long _dfs(long long d, long long x, long long y) {
  if (d == p.size()) {
    long long n = abs(y / x);
    sum += n * (n + 1) / 2 * x;
    return y / x;
  }
  return (_dfs(d + 1, x, y) + _dfs(d + 1, -x * p[d], y));
}
int gcdnumber(long long a, long long y) {
  p.clear();
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      p.push_back(i);
      while (a % i == 0) a /= i;
    }
  }
  sum = 0;
  if (a != 1) p.push_back(a);
  return _dfs(0, 1, y);
}
long long calc(long long radiu, int add) {
  long long y = radiu;
  long long ret = 0;
  for (long long i = 1; i <= radiu; i++) {
    while (y && i * i + y * y > radiu * radiu - add) y--;
    if (y >= m) y = m;
    if (i <= n && y > 0) {
      long long tmp = gcdnumber(i, y);
      ret += (n - i + 1) * (tmp * (m + 1) - sum);
      ret %= P;
    }
  }
  return ret;
}
int main() {
  cin >> n >> m;
  cin >> l >> r >> P;
  long long ans = 0;
  if (l == 1) ans = n * (m + 1) + m * (n + 1);
  ans %= P;
  ans += (calc(r, 0) - calc(l, 1)) * 2;
  while (ans < 0) ans += P;
  ans %= P;
  cout << ans << endl;
}
