#include <bits/stdc++.h>
using namespace std;
long long n, m, L, R, p;
int f[100005][10], cnt[100005];
long long cal(long long ll, long long rr, long long mul) {
  ll = (ll + mul - 1) / mul, rr = rr / mul;
  return (rr - ll + 1) * (m + 1) - (rr + ll) * (rr - ll + 1) / 2 * mul;
}
int main() {
  cin >> n >> m >> L >> R >> p;
  for (int i = 2; i <= 100000; ++i)
    if (cnt[i] == 0)
      for (int j = i; j <= 100000; j += i) f[j][cnt[j]++] = i;
  long long ans = 0, Min = L, Max = min(R, m), r = min(n, R);
  for (long long d = 1; d <= r; ++d) {
    while (Min > 1 && (Min - 1) * (Min - 1) + d * d >= L * L) --Min;
    while (Max * Max + d * d > R * R) --Max;
    if (Min > Max) continue;
    long long sum = 0;
    for (int i = 0; i < (1 << cnt[d]); ++i) {
      long long mul = 1, fac = 1;
      for (int j = 0; j < cnt[d]; ++j)
        if (i >> j & 1) mul *= f[d][j], fac *= -1;
      sum += fac * cal(Min, Max, mul) % p;
    }
    ans = ((ans + sum * (n - d + 1)) % p + p) % p;
  }
  ans = ans * 2 % p;
  if (L == 1) ans = (ans + n * (m + 1) + (n + 1) * m) % p;
  cout << ans << endl;
  return 0;
}
