#include <bits/stdc++.h>
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
long long prime[100001], mu[100001], top;
long long ans, n, m, l, h, B, lim1, lim2;
bool pri[100001];
int main() {
  scanf("%lld%lld%lld%lld%lld", &n, &m, &l, &h, &B);
  while (n >= 150000)
    ;
  if (n > m) n ^= m ^= n ^= m;
  mu[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!pri[i]) {
      prime[++top] = i;
      mu[i] = -1;
    }
    for (int j = 1; j <= top && i * prime[j] <= n; j++) {
      pri[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        mu[i * prime[j]] = 0;
        break;
      }
      mu[i * prime[j]] = -mu[i];
    }
  }
  if (l <= 1 && h >= 1) ans = ((n * (m + 1)) % B + (m * (n + 1)) % B) % B;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= n / i; j++) {
      if (l <= i * j)
        lim1 = 1;
      else
        lim1 = ceil(sqrt(l * l - (j * i) * (j * i)));
      if (lim1 > m) continue;
      if (i * j >= h) continue;
      lim2 = min(m, floor(sqrt(h * h - (j * i) * (j * i))));
      lim1 = ((lim1 - 1) / i) + 1;
      lim2 /= i;
      ans += (mu[i] * (n - j * i + 1) *
              ((m + 1) * (lim2 - lim1 + 1) -
               ((lim1 + lim2) * (lim2 - lim1 + 1) * i) / 2)) *
             2;
      ans %= B;
    }
  while (ans < 0) ans += B;
  printf("%lld", ans);
}
