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;
long long n, m, l, r, p;
const int maxn = 222222;
long long fac[maxn];
vector<long long> v[maxn];
void init() {
  for (int i = 2; i < maxn; i++)
    if (fac[i] == 0) {
      v[i].push_back(i);
      for (int j = i + i; j < maxn; j += i) {
        fac[j] = i;
        v[j].push_back(i);
      }
    }
}
long long cnt(long long x, long long y) {
  if (x == 1) return y % p;
  int c = v[x].size(), MS = (1 << c);
  long long ans = 0;
  for (int s = 0; s < MS; s++) {
    long long t = 1, cnt = 0;
    for (int i = 0; i < c; i++)
      if ((1 << i) & s) {
        t *= v[x][i];
        cnt++;
      }
    if (cnt & 1)
      ans -= y / t;
    else
      ans += y / t;
    ans = (ans % p) + p;
    ans %= p;
  }
  return ans;
}
long long sum(long long x, long long y) {
  if (x == 1) return (y * (1 + y) / 2) % p;
  int c = v[x].size(), MS = 1 << c;
  long long ans = 0;
  for (int s = 0; s < MS; s++) {
    long long t = 1, cnt = 0;
    for (int i = 0; i < c; i++)
      if ((1 << i) & s) {
        t *= v[x][i];
        cnt++;
      }
    long long ty = y / t;
    if (cnt & 1)
      ans -= t * (ty * (ty + 1) / 2);
    else
      ans += t * (ty * (ty + 1) / 2);
    ans = (ans % p) + p;
    ans %= p;
  }
  return ans;
}
int main() {
  init();
  while (cin >> n >> m >> l >> r >> p) {
    long long ans = 0;
    if (l <= 1 && r >= 1) {
      ans += n * (m + 1) + m * (n + 1);
      ans %= p;
    }
    for (long long dx = 1; dx <= n; dx++) {
      if (dx >= r) break;
      long long ly = ceil(sqrt(1.0 * max(1LL, l * l - dx * dx))),
                ry = floor(sqrt(1.0 * min(m * m, r * r - dx * dx)));
      if (ly > ry) continue;
      long long cn = cnt(dx, ry) - cnt(dx, ly - 1),
                su = sum(dx, ry) - sum(dx, ly - 1);
      cn %= p, su %= p;
      ans += 2LL * (n + 1 - dx) * (cn * (m + 1) - su) % p;
      ans %= p;
    }
    cout << ans << endl;
  }
  return 0;
}
