#include <bits/stdc++.h>
using namespace std;
long long Pier1(long long x) {
  long long p = sqrt(x);
  if (p * p == x) return p;
  return p + 1;
}
long long Pier2(long long x) {
  long long p = sqrt(x);
  return p;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n, m, l, p, MOD;
  cin >> n >> m >> l >> p >> MOD;
  ++n;
  ++m;
  vector<vector<int> > rozk(n);
  for (int i = 2; i < n; ++i) {
    if (rozk[i].size() == 0) {
      rozk[i].push_back(i);
      for (int j = 2 * i; j < n; j += i) rozk[j].push_back(i);
    }
  }
  long long odp = 0;
  if (l == 1) odp = (n * (m - 1) + m * (n - 1)) % MOD;
  for (long long rX = 1; rX <= n - 1; ++rX) {
    long long L = l * l - rX * rX;
    long long P = p * p - rX * rX;
    if (P <= 0) continue;
    L = max(L, (long long)1);
    long long L2 = Pier1(L);
    long long P2 = Pier2(P);
    if (L2 > P2) continue;
    L2 = max(L2, (long long)1);
    P2 = min(P2, m - 1);
    if (L2 > P2) continue;
    long long il = 0, s = 0;
    if (rX == 1) {
      il = P2 - L2 + 1;
      s = (L2 + P2) * il / 2;
    } else {
      for (int mask = 1; mask < (1 << rozk[rX].size()); ++mask) {
        long long ilo = 1;
        for (int i = 0; i < rozk[rX].size(); ++i)
          if ((mask & (1 << i)) > 0) ilo *= rozk[rX][i];
        long long a = L2 - L2 % ilo;
        if (L2 % ilo != 0) a += ilo;
        long long b = P2 - P2 % ilo;
        if (a <= b) {
          long long ile = (b - a) / ilo + 1;
          long long suma = (a + b) * ile / 2;
          if (__builtin_popcount(mask) % 2 == 1) {
            il += ile;
            s += suma;
          } else {
            il -= ile;
            s -= suma;
          }
        }
      }
      il = (P2 - L2 + 1) - il;
      s = (L2 + P2) * (P2 - L2 + 1) / 2 - s;
    }
    long long drugi = il * m % MOD;
    s %= MOD;
    drugi -= s;
    if (drugi < 0) drugi += MOD;
    odp = (odp + 2 * ((n - rX) * drugi) % MOD) % MOD;
  }
  cout << odp;
  return 0;
}
