#include <bits/stdc++.h>
long long m, n, l, r, p, num[100005], d[100005][6], ans, ii;
long long tt(long long ql, long long qh, long long mm) {
  qh = qh / mm;
  ql = (ql + mm - 1) / mm;
  return ((qh - ql + 1) * (n + 1) -
          mm * ((qh * (qh + 1) - (ql - 1) * ql) / 2)) %
         p;
}
int main() {
  scanf("%lld%lld", &n, &m);
  scanf("%lld%lld%lld", &l, &r, &p);
  for (int i = 2; i <= m; i++)
    if (num[i] == 0)
      for (int j = i; j <= m; j += i) d[j][num[j]++] = i;
  long long lo = l;
  long long hi = r;
  long long minn = (m < r ? m : r);
  for (long long w = 1; w <= minn; w++) {
    while (lo > 1 && l * l - w * w <= (lo - 1) * (lo - 1)) lo--;
    while (r * r - w * w < hi * hi) hi--;
    if (lo <= hi && lo <= n) {
      long long a = 0;
      int t = (1 << num[w]);
      for (int i = 0; i < t; i++) {
        ii = i;
        long long p1 = 1;
        long long p2 = 1;
        for (int j = 0; j < num[w]; j++) {
          if (ii & 1) {
            p1 *= d[w][j];
            p2 *= -1;
          }
          ii >>= 1;
        }
        a += p2 * tt(lo, hi < n ? hi : n, p1);
      }
      ans = (ans + a * (m - w + 1)) % p;
      if (ans < 0) ans += p;
    }
  }
  if (l <= 1 && r >= 1)
    ans = (2 * ans + m * (n + 1) + n * (m + 1)) % p;
  else
    ans = (2 * ans) % p;
  printf("%d\n", ans);
}
