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;
vector<int> t[100005];
int n, m, l, r, P, i, j, num, t1, t2, flag, q, k;
int calc(int q, int k) {
  k = min(k, m);
  long long num = k / q;
  long long ans = num * (m + 1);
  ans -= num * (num + 1) / 2 * q;
  return (ans + P) % P;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 2; i <= n; i++) {
    if (!t[i].size())
      for (j = i; j <= n; j += i) t[j].push_back(i);
  }
  scanf("%d%d%d", &l, &r, &P);
  long long ans = 0;
  if (l <= 1) ans += (long long)(n + 1) * m + (long long)(m + 1) * n, ans %= P;
  for (i = 1; i < r && i <= n; i++) {
    num = t[i].size();
    t1 = (int)sqrt(max((long long)l * l - (long long)i * i - 1, 0LL));
    t2 = (int)sqrt((long long)r * r - (long long)i * i);
    if (t1 == t2) continue;
    long long res = 0;
    for (j = 0; j < 1 << num; j++) {
      flag = 1;
      q = 1;
      for (k = 0; k < num; k++)
        if (j & (1 << k)) {
          q *= t[i][k];
          flag = -flag;
        }
      res = (res + (calc(q, t2) - calc(q, t1)) * flag + P) % P;
    }
    res *= 2;
    ans = (ans + res * (n - i + 1)) % P;
  }
  printf("%d\n", ans % P);
}
