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-8);
long long n, m, l, r, p;
long long prime[100010], d[100010];
void GetPrime() {
  d[1] = 1;
  for (long long i = 2; i <= 100000; i++) {
    if (prime[i]) continue;
    for (long long j = 1; i * j <= 100000; j++)
      prime[i * j] = i, d[i * j] = d[j] * -1;
  }
}
long long x[110], y[110];
int len;
vector<long long> vec;
void Dfs(long long p, long long tmp, long long m) {
  if (p == len) {
    if (tmp <= m) vec.push_back(tmp);
    return;
  }
  Dfs(p + 1, tmp * x[p], m);
  Dfs(p + 1, tmp, m);
}
long long Calc(long long n, long long m, long long l) {
  long long ret = 0, tmp = n;
  len = 0;
  while (n != 1) {
    x[len] = prime[n];
    while (n % x[len] == 0) {
      n /= x[len];
    }
    len++;
  }
  vec.clear();
  Dfs(0, 1, m);
  for (int i = 0; i < (int)vec.size(); i++) {
    long long k = vec[i];
    ret += d[k] * ((m / k) * (l + 1) - (m / k) * ((m / k) + 1) / 2LL * k);
  }
  return ret;
}
long long Solve(long long r, long long add) {
  long long ret = 0;
  for (long long i = 1; i <= r; i++) {
    if (i > m) break;
    if (r * r - add - i * i < 0) break;
    long long j = (long long)sqrt(r * r - add - i * i);
    j = min(j, n);
    if (j <= 0) continue;
    ret += Calc(i, j, n) * (m - i + 1) % p;
    ret %= p;
  }
  return ret;
}
int main() {
  GetPrime();
  cin >> n >> m;
  cin >> l >> r >> p;
  long long ans = 0;
  if (l == 1) ans += (n + 1) * m + (m + 1) * n;
  ans %= p;
  ans += 2LL * (Solve(r, 0) - Solve(l, 1));
  ans %= p;
  ans = (ans + p) % p;
  cout << ans << endl;
  return 0;
}
