#include <bits/stdc++.h>
using namespace std;
long long n, m;
double rMin, rMax;
double eps = 1e-8;
long long mod;
vector<int> factor[100001];
long long F[100001];
long long S(long long x) { return x * (x + 1) / 2; }
long long C(long long x) { return x; }
long long gcd(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long cnt(long long x, long long t) {
  long long ret = 0;
  for (int i = 0; i < factor[t].size(); i++) {
    long long v = factor[t][i];
    ret += F[v] * C(x / v);
    ret %= mod;
  }
  return ret;
}
long long sum(long long x, long long t) {
  long long ret = 0;
  for (int i = 0; i < factor[t].size(); i++) {
    long long v = factor[t][i];
    ret += ((F[v] * S(x / v)) % mod) * v;
    ret %= mod;
  }
  return ret;
}
long long calc(int n, int m, double r, bool include) {
  long long ret = 0;
  for (int dx = 0; dx <= n; dx++) {
    double t = r * r - 1.0 * dx * dx + (include ? eps : -eps);
    if (t < 0) continue;
    long long v = (int)sqrt(t);
    v = min(v, (long long)m);
    long long now = 0;
    if (dx == 0) {
      if (v == 0)
        now = (long long)(n - dx + 1) * (m + 1);
      else
        now = (long long)(n - dx + 1) * (m + 1 + m);
    } else {
      if (dx == 1) now += 1LL * (long long)(n - dx + 1) * (m + 1);
      if (v > 0) {
        long long c = cnt(v, dx);
        now += 2LL * (long long)(n - dx + 1) * (c * (m + 1) - sum(v, dx));
      }
    }
    ret += now;
    ret %= mod;
  }
  return ret;
}
long long calc(int n, int m, double rMin, double rMax) {
  long long ret = calc(n, m, rMax, true) - calc(n, m, rMin, false);
  ret %= mod;
  ret += mod;
  ret %= mod;
  return ret;
}
int MAIN() {
  cin >> n >> m >> rMin >> rMax >> mod;
  F[1] = 1;
  for (int i = 1; i <= 100000; i++) {
    if (i != 1) F[i] = -F[i];
    factor[i].push_back(i);
    for (int j = i + i; j <= 100000; j += i) {
      F[j] += F[i];
      F[j] %= mod;
      factor[j].push_back(i);
    }
  }
  cout << calc(n, m, rMin, rMax) << endl;
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  return MAIN();
}
