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;
const int nmax = 1.5e5 + 5;
long long sign[2] = {1, -1};
bool prime[nmax], cnt_div[nmax], uniq[nmax];
long long n, m, l, r, mod;
long long cnt_mult(long long lo, long long hi, long long j) {
  if (lo > hi) return 0;
  return max(0LL, (hi / j)) - max(0LL, ((lo - 1) / j));
}
long long sum_mult(long long lo, long long hi, long long j) {
  if (lo > hi) return 0;
  long long cnt = cnt_mult(lo, hi, j);
  long long lo_mult = lo + (j - (lo % j)) % j;
  long long hi_mult = hi - hi % j;
  long long ans = ((hi_mult + lo_mult) * cnt) / 2;
  return ans % mod;
}
long long cnt_coprime(long long lo, long long hi, long long i) {
  long long ans = 0;
  for (long long j = 1; j * j <= i; ++j) {
    if (i % j != 0) continue;
    if (uniq[j]) ans += sign[cnt_div[j]] * cnt_mult(lo, hi, j);
    if (i / j != j && uniq[i / j])
      ans += sign[cnt_div[i / j]] * cnt_mult(lo, hi, i / j);
    ans %= mod;
  }
  return ans;
}
long long sum_coprime(long long lo, long long hi, long long i) {
  long long ans = 0;
  for (long long j = 1; j * j <= i; ++j) {
    if (i % j != 0) continue;
    if (uniq[j]) ans += sign[cnt_div[j]] * sum_mult(lo, hi, j);
    if (i / j != j && uniq[i / j])
      ans += sign[cnt_div[i / j]] * sum_mult(lo, hi, i / j);
    ans %= mod;
  }
  return ans;
}
long long cnt_coprime(long long i) {
  long long lo = sqrt(l * l - i * i) + 1 - eps;
  long long hi = sqrt(r * r - i * i) + eps;
  lo = max(lo, 1LL);
  hi = min(hi, m);
  return cnt_coprime(lo, hi, i);
}
long long sum_coprime(long long i) {
  long long lo = sqrt(l * l - i * i) + 1 - eps;
  long long hi = sqrt(r * r - i * i) + eps;
  lo = max(lo, 1LL);
  hi = min(hi, m);
  return sum_coprime(lo, hi, i);
}
int main() {
  fill(prime + 2, prime + nmax, true);
  fill(uniq + 1, uniq + nmax, true);
  for (long long i = 2; i < nmax; ++i) {
    if (prime[i]) {
      for (long long j = i; j < nmax; j += i) {
        prime[j] = false;
        cnt_div[j] ^= 1;
      }
      for (long long j = i * i; j < nmax; j += i * i) uniq[j] = false;
    }
  }
  cin >> n >> m >> l >> r >> mod;
  long long ans = (((n + 1) * m + (m + 1) * n) % mod) * (l == 1);
  n++, m++;
  for (int i = 1; i <= min(r, n); ++i) {
    long long cnt = cnt_coprime(i);
    long long sum = sum_coprime(i);
    long long cur = 0;
    cur += cnt * n % mod * m;
    cur -= sum * n;
    cur -= cnt * i % mod * m;
    cur += sum * i;
    ans = (ans + 2 * cur) % mod;
  }
  cout << (ans + mod) % mod << '\n';
};
