#include <bits/stdc++.h>
using namespace std;
int facs[25], pn, upper, res2, M, N, MOD;
long long res, ans;
void go(int ind, int v, bool parity) {
  if (ind == pn) {
    int nums = upper / v + 1;
    long long a = (long long)nums * ((nums - 1) * v) / 2;
    if (parity) {
      res -= a;
      res2 -= nums;
    } else {
      res += a;
      res2 += nums;
    }
    return;
  }
  go(ind + 1, v, parity);
  go(ind + 1, v * facs[ind], !parity);
}
int getans(long long RR) {
  ans = 0;
  for (int x = 1; x <= N; ++x) {
    long long xx = (long long)x * x;
    if (xx > RR) break;
    int p = 2, n = x;
    pn = 0;
    while (p * p <= n) {
      if (n % p == 0) {
        while (n % p == 0) n /= p;
        facs[pn++] = p;
      }
      ++p;
    }
    if (n > 1) {
      facs[pn++] = n;
    }
    upper = min(M, (int)sqrt(RR - xx + 1e-7));
    res = 0;
    res2 = 0;
    go(0, 1, 0);
    res %= MOD;
    long long val = ((long long)res2 * (M + 1) - res) * 2;
    if (x == 1) {
      val -= M + 1;
    }
    val %= MOD;
    ans = (ans + val * (N - x + 1)) % MOD;
  }
  if (RR >= 1) {
    ans += (long long)(N + 1) * M;
  }
  return ans % MOD;
}
int main() {
  int L, R;
  scanf("%d%d%d%d%d", &N, &M, &L, &R, &MOD);
  long long LL = (long long)L * L;
  long long RR = (long long)R * R;
  printf("%d\n", (getans(RR) - getans(LL - 1) + MOD) % MOD);
}
