#include <bits/stdc++.h>
int fa[100005][20];
int fn[100005];
int p;
void init(int m) {
  for (int i = 2; i <= m; ++i) {
    if (!fn[i]) {
      fa[i][fn[i]++] = i;
      for (int j = i + i; j <= m; j += i) fa[j][fn[j]++] = i;
    }
  }
}
long long n, m;
long long sum(long long f, long long x) {
  long long k = x / f;
  k = ((n + 1) * k - (k + 1) * k * f / 2) % p;
  return k < 0 ? k + p : k;
}
long long calc(long long f, long long l, long long r) {
  long long k = (sum(f, r) - sum(f, l - 1)) % p;
  return k < 0 ? k + p : k;
}
int main(int argc, char const *argv[]) {
  long long l, r, ans = 0;
  scanf("%I64d%I64d", &n, &m);
  scanf("%I64d%I64d%d", &l, &r, &p);
  init(m);
  long long lx = l;
  long long rx = r;
  long long ret = 0;
  for (long long dy = 1; dy <= (m < r ? m : r); ++dy) {
    while (lx > 1 && l * l - dy * dy <= (lx - 1) * (lx - 1)) --lx;
    while (r * r - dy * dy < rx * rx) --rx;
    long long s = 0;
    if (lx <= rx && lx <= n) {
      for (int i = 0; i < (1 << fn[dy]); ++i) {
        long long f = 1;
        long long t = 1;
        for (int j = 0; j < fn[dy]; ++j) {
          if (i & (1 << j)) {
            f *= fa[dy][j];
            t *= -1;
          }
        }
        s += t * calc(f, lx, (rx < n ? rx : n));
      }
    }
    ans = (ans + s * (m + 1 - dy)) % p;
    ans = (ans < 0 ? ans + p : ans);
  }
  if (l <= 1 && r >= 1)
    ans = (ans * 2 + (n + 1) * m + n * (m + 1)) % p;
  else
    ans = (ans * 2) % p;
  printf("%I64d\n", ans);
  return 0;
}
