#include <bits/stdc++.h>
using namespace std;
vector<int> s[100005];
long long int n, m, l, r, p, ans = 0, sum = 0, i, j, k;
long long int calc(long long int s, long long int r) {
  r = min(r, m);
  long long int tmp, num = r / s;
  tmp = num * (m + 1) - num * (num + 1) / 2 * s;
  return tmp % p;
}
int main() {
  scanf("%lld%lld%lld%lld%lld", &n, &m, &l, &r, &p);
  for (i = 2; i <= n; i++) {
    if (s[i].size()) continue;
    for (j = i; j <= n; j += i) s[j].push_back(i);
  }
  if (l == 1) ans = (n * (m + 1) + m * (n + 1)) % p;
  for (i = 1; i <= n && i <= r; i++) {
    long long L = sqrt(l * l - i * i - 1), R = sqrt(r * r - i * i);
    if (L < 0) L = 0;
    if (L == R) continue;
    long long int v, flag, num = s[i].size();
    sum = 0;
    for (j = 0; j < (1 << num); j++) {
      v = flag = 1;
      for (k = 0; k < num; k++)
        if (j & (1 << k)) v *= s[i][k], flag *= -1;
      sum = (sum + (calc(v, R) - calc(v, L)) * flag + p) % p;
    }
    sum *= 2;
    ans = (ans + sum * (n - i + 1)) % p;
  }
  printf("%lld\n", ans);
}
