#include <bits/stdc++.h>
using namespace std;
vector<long long> di[150005];
long long n, m, l, r, mod;
long long calc(long long lb, long long ub, long long mul) {
  ub = ub / mul;
  lb = (lb + mul - 1) / mul;
  long long sum = (ub - lb + 1LL) * (m + 1);
  sum -= (ub * (ub + 1) - (lb - 1) * lb) / 2 * mul;
  sum = (sum % mod + mod) % mod;
  return sum;
}
int main() {
  scanf("%lld %lld %lld %lld %lld", &n, &m, &l, &r, &mod);
  long long lb = l, ub = r;
  for (int i = 2; i <= 150000; i++) {
    if (!di[i].empty()) continue;
    for (int j = i; j <= 150000; j += i) {
      di[j].push_back(i);
    }
  }
  long long ret = 0LL;
  for (long long i = 1; i <= min(n, r); i++) {
    while (lb > 1 && l * l - i * i <= (lb - 1) * (lb - 1)) lb--;
    while (r * r - i * i < ub * ub) ub--;
    if (lb <= ub && lb <= m) {
      long long res = 0;
      int mask = (1 << (di[i].size()));
      for (int j = 0; j < mask; j++) {
        long long mul = 1;
        int flag = 1;
        for (int k = 0; k < di[i].size(); k++) {
          if (((j >> k) & 1)) {
            mul *= di[i][k];
            flag *= (-1);
          }
        }
        res += flag * calc(lb, min(ub, m), mul);
      }
      ret = (ret + res * (n - i + 1)) % mod;
      ret = (ret + mod) % mod;
    }
  }
  if (l <= 1 && 1 <= r)
    ret = (ret * 2LL + n * (m + 1) + m * (n + 1)) % mod;
  else
    ret = (ret * 2LL) % mod;
  cout << ret << endl;
}
