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;
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
const int MX = 1e5 + 1;
vector<int> divs[MX];
int mu[MX];
int p;
long long count(long long m, int n) {
  long long res = m;
  for (int d : divs[n]) {
    res += mu[d] * m / d;
  }
  return res % p;
}
long long sum(long long m, int n) {
  long long res = m * (m + 1) / 2;
  for (int d : divs[n]) {
    res += mu[d] * d * (m / d) * (m / d + 1) / 2;
  }
  return res % p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  long long n, m;
  long long l, r;
  cin >> n >> m >> l >> r >> p;
  l *= l;
  r *= r;
  for (int d = 2; d <= n; ++d) {
    for (int j = d; j <= n; j += d) divs[j].push_back(d);
  }
  mu[1] = 1;
  for (int j = 2; j <= n; ++j) {
    int pr = divs[j][0];
    if ((j / pr) % pr == 0)
      mu[j] = 0;
    else
      mu[j] = -mu[j / pr];
  }
  long long res = 0;
  for (int i = (1); i <= (n); ++i) {
    long long sq = (long long)i * i;
    int b, e;
    int bb = 1, be = m + 1;
    while (bb != be) {
      long long med = (bb + be) / 2;
      if (sq + med * med < l)
        bb = med + 1;
      else
        be = med;
    }
    b = bb;
    bb = 0, be = m;
    while (bb != be) {
      long long med = (bb + be + 1) / 2;
      if (sq + med * med > r)
        be = med - 1;
      else
        bb = med;
    }
    e = bb;
    long long cur = ((m + 1) * (count(e, i) - count(b - 1, i) + p) + p -
                     sum(e, i) + sum(b - 1, i)) %
                    p;
    cur = (cur % p + p) % p;
    res = (res + cur * (n + 1 - i)) % p;
  }
  res *= 2;
  if (l == 1) res += ((n + 1) * m + (m + 1) * n);
  cout << res % p << endl;
  return 0;
}
