#include <bits/stdc++.h>
int FASTBUFFER;
using namespace std;
void dfs(long long i, long long p, long long s);
long long calc(long long Min, long long Max, long long x);
long long n, m, l, r, mo, i, j, ans, now, a, tot, Min, Max, b[14];
long long Hash[100000 + 5];
long long sq[100000 + 5][14];
int main() {
  for (i = 2; i <= 100000; i++) {
    if (Hash[i] == 1) continue;
    for (j = i; j <= 100000; j += i) sq[j][++sq[j][0]] = i, Hash[j] = 1;
  }
  cin >> n >> m >> l >> r >> mo;
  if (l == 1) ans += (n + 1) * m % mo;
  ans %= mo;
  for (a = 1; a <= r && a <= n; a++) {
    tot = sq[a][0];
    for (j = 1; j <= tot; j++) b[j] = sq[a][j];
    if (a > l)
      Min = 0;
    else
      Min = (long long)sqrt(l * l - a * a);
    while (Min * Min + a * a < l * l) Min++;
    Max = (long long)sqrt(r * r - a * a) + 5;
    while (Max * Max + a * a > r * r) Max--;
    Max = min(Max, m);
    if (Min > Max) continue;
    now = 0;
    dfs(1, 1, 0);
    ans += (now * (n - a + 1)) % mo;
    ans %= mo;
  }
  cout << ans << endl;
  return 0;
}
void dfs(long long i, long long p, long long s) {
  if (i > tot) {
    if (s)
      now -= calc(Min, Max, p);
    else
      now += calc(Min, Max, p);
    now %= mo;
    while (now < 0) now += mo;
    now %= mo;
    return;
  }
  dfs(i + 1, p * b[i], 1 - s);
  dfs(i + 1, p, s);
}
long long calc(long long Min, long long Max, long long x) {
  long long l = Min / x * x, r = Max / x * x;
  long long a, b, c;
  if (Min % x) l += x;
  a = (m - r + 1) + (m - r + 1);
  b = (m - l + 1) + (m - l + 1);
  c = (r - l) / x + 1;
  if (l == 0)
    return (a + b) * c / 2 - (m - l + 1);
  else
    return (a + b) * c / 2;
}
