#include <bits/stdc++.h>
using namespace std;
long long gcd(long long u, long long v) {
  while (v != 0) {
    long long r = u % v;
    u = v;
    v = r;
  }
  return u;
}
int h, w, l, r, MOD;
int n, p[100];
int d[100001];
int ly, hy;
long long cnt, sum;
void go(int at, int step, int by) {
  if (at < n) {
    go(at + 1, step, +by);
    go(at + 1, step * p[at], -by);
  } else {
    int a = (ly + step - 1) / step;
    int b = hy / step;
    if (a > b) return;
    cnt += (b - a + 1) * by;
    sum += (long long)(a + b) * step * (b - a + 1) / 2 * by;
  }
}
void run() {
  memset(d, -1, sizeof(d));
  for (int i = (2); i <= (100000); ++i)
    if (d[i] == -1) {
      d[i] = i;
      if ((long long)i * i <= 100000)
        for (int j = i * i; j <= 100000; j += i)
          if (d[j] == -1) d[j] = i;
    }
  scanf("%d%d%d%d%d", &h, &w, &l, &r, &MOD);
  long long ret = 0;
  if (l <= 1 && 1 <= r) ret += (long long)(h + 1) * w;
  if (l <= 1 && 1 <= r) ret += (long long)h * (w + 1);
  for (int dx = (1); dx <= (h); ++dx) {
    long long ly2 = (long long)l * l - (long long)dx * dx;
    if (ly2 <= 0)
      ly = 1;
    else {
      ly = (int)sqrt(ly2);
      if ((long long)ly * ly < ly2) ++ly;
    }
    long long hy2 = (long long)r * r - (long long)dx * dx;
    if (hy2 < 0)
      hy = 0;
    else
      hy = (int)sqrt(hy2);
    hy = min(hy, w);
    cnt = 0, sum = 0;
    n = 0;
    for (int z = dx; z != 1;) {
      p[n] = d[z];
      while (z % p[n] == 0) z /= p[n];
      ++n;
    }
    go(0, 1, +1);
    ret += 2LL * (h - dx + 1) * cnt * (w + 1) % MOD;
    ret -= 2LL * (h - dx + 1) * sum % MOD;
    ret %= MOD;
    if (ret < 0) ret += MOD;
  }
  ret %= MOD;
  if (ret < 0) ret += MOD;
  cout << ret << endl;
}
int main() {
  run();
  return 0;
}
