This problem was deleted from the contest, because it was used previously at another competition.

Input

Output

Examples

Input

1 1
1 2 100


Output

6
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
inline int jud(double a, double b) {
  if (abs(a) < eps && abs(b) < eps)
    return 0;
  else if (abs1(a - b) / abs1(a) < eps)
    return 0;
  if (a < b) return -1;
  return 1;
}
const int maxn = 200000;
int mod;
vector<int> have[maxn];
int n, m, l, r, p;
long long dengcha(long long pri, long long n) {
  return n * (n + 1) / 2 % mod * pri % mod;
}
inline long long justdoit(long long n, long long m, double maxl) {
  long long ans = 0;
  for (long long i = (long long)maxl, link = 1; i > 0; i--)
    if (i <= n) {
      while (jud(1.0 * hypot(i, link), maxl) != 1 && link <= m) link++;
      link--;
      link = min(link, m);
      long long cnt = 0, rcnt = 0;
      for (int mask = 0; mask < 1 << (have[i].size()); mask++) {
        long long co = __builtin_popcount(mask) & 1;
        co = -(co * 2 - 1);
        long long num = 1;
        for (int j = 0; j < (int)have[i].size(); j++) {
          if (mask & (1 << j)) num *= have[i][j];
        }
        cnt += co * dengcha(num, link / num);
        rcnt += co * link / num;
      }
      cnt = rcnt * (m + 1) - cnt;
      cnt %= mod;
      ans = (ans + cnt * (n - i + 1) % mod) % mod;
    }
  return ans % mod;
}
int main() {
  scanf("%d%d%d%d%d", &n, &m, &l, &r, &mod);
  for (int i = 2; i < maxn; i++)
    if (have[i].size() == 0)
      for (int j = i; j < maxn; j += i) have[j].push_back(i);
  long long ans =
      (justdoit(n, m, r) + mod - justdoit(n, m, l - 0.000001)) % mod;
  ans *= 2;
  if (l == 1) ans += 1ll * n * (m + 1) % mod + 1ll * m * (n + 1) % mod;
  cout << ans % mod << endl;
  return 0;
}
