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;
void _fill_int(int* p, int val, int rep) {
  int i;
  for (i = 0; i < rep; i++) p[i] = val;
}
signed long long GETi() {
  signed long long i;
  scanf("%lld", &i);
  return i;
}
signed long long N, M, L, R, P;
signed long long XL[160001], XR[160001];
vector<signed long long> S[100001];
vector<signed long long> enumdiv(signed long long n) {
  vector<signed long long> V;
  for (signed long long i = 2; i * i <= n; i++) {
    if (n % i == 0) V.push_back(i);
    while (n % i == 0) n /= i;
  }
  if (n > 1) V.push_back(n);
  return V;
}
void solve() {
  int f, i, j, k, l, x, y;
  cin >> N >> M >> L >> R >> P;
  signed long long ret = 0;
  if (L == 1) ret = (N * (M + 1) + M * (N + 1)) % P;
  S[1].push_back(0);
  for (i = 1; i <= N; i++) S[1].push_back((N + 1 - i) % P);
  for (i = 2; i <= M; i++) {
    S[i].push_back(0);
    for (j = 1; j * i <= N; j++)
      S[i].push_back((S[i].back() + S[1][j * i]) % P);
  }
  for (i = 1; i <= N; i++) S[1][i] = (S[1][i] + S[1][i - 1]) % P;
  for (y = R - 1; y > 0; y--) {
    XL[y] = XL[y + 1];
    XR[y] = XR[y + 1];
    while (XL[y] * XL[y] + y * (signed long long)y < L * L) XL[y]++;
    while (XR[y] * XR[y] + y * (signed long long)y <= R * R) XR[y]++;
    XR[y]--;
  }
  for (y = 1; y <= min(M, R); y++) {
    signed long long line = 0;
    if (XL[y] == 0) XL[y]++;
    if (XL[y] > N) continue;
    if (XR[y] > N) XR[y] = N;
    vector<signed long long> D = enumdiv(y);
    for (i = 0; i < 1 << D.size(); i++) {
      k = 1;
      l = (__builtin_popcount(i) % 2) ? -1 : 1;
      for (j = 0; j < D.size(); j++)
        if (i & (1 << j)) k *= D[j];
      line += l * (S[k][XR[y] / k] - S[k][(XL[y] - 1) / k]);
      line %= P;
      if (line < 0) line += P;
    }
    ret += (line * 2) % P * (M + 1 - y);
    ret %= P;
    if (ret < 0) ret += P;
  }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  if (argc == 1) ios::sync_with_stdio(false);
  for (int i = 1; i < argc; i++) s += argv[i], s += '\n';
  for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin);
  solve();
  return 0;
}
