#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
long long n, m, ll, rr, p, tot, f[40];
long long cal(long long x) { return 1ll * x * (x + 1) / 2; }
long long dfs(long long x, long long y, long long st) {
  long long re = 0;
  for (long long i = st; i < tot; ++i) {
    re += cal(y / (x * f[i])) * (x * f[i]) - dfs(x * f[i], y, i + 1);
  }
  return re;
}
long long dfs1(long long x, long long y, long long st) {
  long long re = 0;
  for (long long i = st; i < tot; ++i) {
    re += y / (x * f[i]) - dfs1(x * f[i], y, i + 1);
  }
  return re;
}
long long go(long long x, long long y) {
  if (x == 1)
    return (m + 1) * y - cal(y);
  else {
    tot = 0;
    for (long long i = 2; i * i <= x; ++i) {
      if (x % i == 0) {
        f[tot++] = i;
        while (x % i == 0) x /= i;
      }
    }
    if (x > 1) f[tot++] = x;
    return (y - dfs1(1, y, 0)) * (m + 1) + dfs(1, y, 0) - cal(y);
  }
}
int main() {
  long long t, x, y, z, ca = 1;
  scanf("%I64d%I64d", &(n), &(m));
  scanf("%I64d%I64d%I64d", &(ll), &(rr), &(p));
  long long ans = 0;
  long long l, r;
  for (long long i = (int)(1); i <= (int)(n); ++i) {
    if (i >= rr) break;
    if (i >= ll)
      l = 1;
    else
      l = (int)sqrt(1.0 * ll * ll - 1.0 * i * i - 0.5) + 1;
    r = (int)sqrt(1.0 * rr * rr - 1.0 * i * i + 0.5);
    if (l > m) l = m + 1;
    if (r > m) r = m;
    if (r >= l) {
      ans = (ans + (n + 1 - i) * (go(i, r) - go(i, l - 1))) % p;
    }
  }
  ans <<= 1;
  ans %= p;
  if (ll == 1) ans = (ans + n * (m + 1) * 1ll + m * (n + 1) * 1ll) % p;
  printf("%d\n", ((int)ans));
  return 0;
}
