#include <bits/stdc++.h>
using namespace std;
int n, m, p[200000], miu[200000], MOD;
bool mark[200000];
void init() {
  miu[1] = 1;
  for (int i = 2; i < 200000; ++i) {
    if (!mark[i]) p[++p[0]] = i, miu[i] = -1;
    for (int j = 1; j <= p[0] && p[j] * i < 200000; ++j) {
      mark[i * p[j]] = true;
      if (i % p[j] == 0) {
        miu[i * p[j]] = 0;
        break;
      }
      miu[i * p[j]] = -miu[i];
    }
  }
}
int work(long long lim) {
  if (lim <= 0) return 0;
  int res = 0;
  for (int d = 1; d <= n && d <= m; ++d)
    for (int x = d; x <= n; x += d)
      if (x % d == 0) {
        if (lim < 1ll * x * x) break;
        int A = sqrt(lim - 1ll * x * x), mul = (n - x + 1);
        long long B = std::min(m / d, A / d);
        res = (res + 1ll * mul * miu[d] *
                         ((B * (m + 1) - (B + 1) * B / 2 * d) % MOD) % MOD) %
              MOD;
      }
  return res * 2 % MOD;
}
int main() {
  int l, r;
  cin >> n >> m >> l >> r >> MOD;
  init();
  int ans = (work(1ll * r * r) - work(1ll * l * l - 1)) % MOD;
  if (l == 1) ans += (1ll * n * (m + 1) + 1ll * m * (n + 1)) % MOD;
  ans %= MOD;
  cout << (ans + MOD) % MOD << endl;
}
