#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long n, m, l, r, lsq, rsq, mod, ans, x, y, tmp, p, flag;
int num[N], fac[N][8];
long long calc(long long x, long long t) {
  x = min(x, m);
  long long tmp = x / t;
  long long ans = tmp * (m + 1) - (1 + tmp) * tmp / 2 * t;
  return ans % mod;
}
int main() {
  scanf("%lld%lld", &n, &m);
  scanf("%lld%lld%lld", &l, &r, &mod);
  for (long long i = 2; i <= n; i++)
    if (!num[i])
      for (long long j = i; j <= n; j += i) fac[j][++num[j]] = i;
  lsq = l * l;
  rsq = r * r;
  if (l <= 1) ans = (long long)(n + 1) * m % mod + (long long)n * (m + 1) % mod;
  for (long long i = 1; i <= n; i++) {
    if (i >= r) break;
    x = (long long)sqrt(max(lsq - i * i - 1, 0LL));
    y = (long long)sqrt(rsq - i * i);
    if (x == y) continue;
    long long tx = 0, ty = 0;
    for (long long j = 0; j < (1 << num[i]); j++) {
      p = flag = 1;
      for (long long k = 0; k < num[i]; k++)
        if (j & (1 << k)) {
          p *= fac[i][k + 1];
          flag = -flag;
        }
      tx = (tx + calc(x, p) * flag + mod) % mod;
      ty = (ty + calc(y, p) * flag + mod) % mod;
    }
    tmp = ((ty - tx + mod) << 1) % mod;
    (ans += tmp * (n - i + 1)) %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
