This problem was deleted from the contest, because it was used previously at another competition.

Input

Output

Examples

Input

1 1
1 2 100


Output

6
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, m, p;
int a[100], fac[maxn];
void init() {
  for (int i = 2; i <= 100000; i++)
    if (!fac[i]) {
      fac[i] = i;
      if ((long long)i * i > 100000) continue;
      for (int j = i * i; j <= 100000; j += i)
        if (!fac[j]) fac[j] = i;
    }
}
int solve(int x, int y) {
  if (y == 0) return 0;
  int N = 0;
  for (int k = x; k > 1; k /= fac[k])
    if (N == 0 || fac[k] != a[N - 1]) a[N++] = fac[k];
  int res = 0;
  for (int mask = 0; mask < (1 << N); mask++) {
    int cnt = 1, tot = 0;
    for (int i = 0; i < N; i++)
      if (mask >> i & 1) {
        cnt *= a[i];
        tot++;
      }
    int t = y / cnt;
    if (tot & 1)
      res = ((res -
              ((long long)(m + 1) * t - (long long)(cnt + cnt * t) * t / 2)) %
                 p +
             p) %
            p;
    else
      res = (res +
             ((long long)(m + 1) * t - (long long)(cnt + cnt * t) * t / 2)) %
            p;
  }
  return (long long)res * (n - x + 1) % p;
}
int main() {
  init();
  int l, r;
  cin >> n >> m >> l >> r >> p;
  int res = 0;
  for (int x = 1; x <= n; x++) {
    int lo, hi, mid;
    for (lo = 0, hi = 100001; lo < hi;) {
      mid = (lo + hi) / 2;
      (long long)x* x + (long long)mid* mid >= (long long)l* l ? hi = mid
                                                               : lo = mid + 1;
    }
    int L = lo;
    for (lo = 0, hi = 100001; lo < hi;) {
      mid = (lo + hi) / 2 + 1;
      (long long)x* x + (long long)mid* mid <= (long long)r* r ? lo = mid
                                                               : hi = mid - 1;
    }
    int R = lo;
    L = max(L, 1);
    R = min(R, m);
    if (L > R) continue;
    res = (res + solve(x, R)) % p;
    res = (res + p - solve(x, L - 1)) % p;
  }
  res = (long long)res * 2 % p;
  if (l <= 1) res = ((long long)n * (m + 1) + (long long)m * (n + 1) + res) % p;
  cout << res << endl;
  return 0;
}
