#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int MOD = 1000000007;
long long n, m, p;
long long query(long long r) {
  int i, j;
  long long ret = 0;
  for (i = 1; i <= n && i * 1LL * i < r; i++) {
    long long mx = sqrt(r - 1LL * i * i) + 1;
    while (mx * mx + 1LL * i * i > r) mx--;
    if (mx > m) mx = m;
    long long per = n - i + 1;
    long long cnt = 0;
    long long sum = 0;
    set<int> S;
    int tp = i;
    for (j = 2; j * j <= tp; j++)
      while (tp % j == 0) tp /= j, S.insert(j);
    if (tp > 1) S.insert(tp);
    vector<int> L(S.begin(), S.end());
    for (j = 0; j < 1 << L.size(); j++) {
      long long num = __builtin_popcount(j);
      long long temp = 1;
      if (num & 1LL) temp *= -1;
      long long z = 1;
      for (int k = 0; k < L.size(); k++)
        if (j >> k & 1) z *= L[k];
      num = mx / z;
      cnt += temp * num;
      sum += temp * z * (1 + num) * num / 2;
    }
    ret += (cnt * (m + 1) - sum) % p * per % p;
    ret %= p;
  }
  return ret;
}
int main() {
  long long l, r;
  while (cin >> n >> m >> l >> r >> p) {
    if (n > m) swap(n, m);
    long long add = 0;
    if (l == 1) add = (n + 1) * m + (m + 1) * n;
    query(l * l - 1);
    cout << ((query(r * r) - query(l * l - 1) + p) * 2LL % p + add) % p << endl;
  }
  return 0;
}
