#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int l, r, p;
int get(int m, int a, int d) {
  int t = a / d;
  return ((long long)(m + 1) * t - (long long)t * (t + 1) * d / 2) % p;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d%d", &l, &r, &p);
  int ans = 0;
  if (l <= 1 && r >= 1) ans = ((long long)2 * n * m + n + m) % p;
  for (int a = 1; a <= n; a++) {
    int b0, b1;
    {
      int cl = 0, cr = m + 1;
      while (cr - cl > 1) {
        int s = (cl + cr) / 2;
        if ((long long)a * a + (long long)s * s < (long long)l * l)
          cl = s;
        else
          cr = s;
      }
      b0 = cl;
    }
    {
      int cl = 0, cr = m + 1;
      while (cr - cl > 1) {
        int s = (cl + cr) / 2;
        if ((long long)a * a + (long long)s * s <= (long long)r * r)
          cl = s;
        else
          cr = s;
      }
      b1 = cl;
    }
    if (b0 < b1) {
      int A = a;
      vector<int> v;
      for (int t = 2; t * t <= A; t++)
        if (A % t == 0) {
          v.push_back(t);
          while (A % t == 0) A /= t;
        }
      if (A > 1) v.push_back(A);
      int cur = 0;
      for (int mask = 0; mask < (1 << ((int)(v).size())); mask++) {
        int tmp = 1, q = 1;
        for (int t = 0; t < ((int)(v).size()); t++)
          if ((mask >> t) & 1) {
            tmp *= v[t];
            q = -q;
          }
        cur = ((long long)cur + q * get(m, b1, tmp) - q * get(m, b0, tmp)) % p;
        if (cur < 0) cur += p;
      }
      ans = (ans + (long long)2 * cur * (n - a + 1)) % p;
    }
  }
  printf("%d\n", ans);
  return 0;
}
