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;
long long f[3][200000];
long long ans[200000];
int P[200000], p;
int qq[200000];
long long l, r;
void add(int x, int l, int r) {
  f[x][l]++;
  f[x][r + 1]--;
}
bool bit(int mask, int x) {
  mask = (mask & (1 << x));
  return (mask > 0);
}
int gcd(int n, int m) {
  while (n && m) {
    if (n > m)
      n %= m;
    else
      m %= n;
  }
  return (n + m);
}
void del(int x) {
  int sz = 0, X = x;
  while (x > 1) {
    qq[sz++] = P[x];
    int d = P[x];
    while (x % d == 0) x /= d;
  }
  for (int i = 0; i < (1 << sz); ++i) {
    int rr = 1;
    for (int j = 0; j < sz; ++j)
      if (bit(i, j)) rr *= qq[j];
    ans[rr] -= f[2][X];
  }
}
int n, m;
long long calc(long long r) {
  if (r == 0) return 0;
  memset(ans, 0, sizeof(ans));
  ans[0] = f[2][1] % p;
  for (int i = 1; i <= m; ++i) {
    int d = i;
    while (d <= m) {
      ans[i] = (ans[i] + f[2][d]) % p;
      d += i;
    }
  }
  long long ret = 0, ri = m;
  for (long long i = 0; i <= n; ++i) {
    long long rd = r - i * i;
    if (rd < 0) break;
    while (ri * ri > rd) {
      del(ri);
      ri--;
    }
    if (i == 0)
      ret = (ret + (ri ? f[2][1] : 0) * f[1][0] % p) % p;
    else {
      if (i == 1) ret = (ret + f[1][i] * f[2][0] % p) % p;
      int sz = 0;
      int x = i;
      while (x > 1) {
        qq[sz++] = P[x];
        int d = P[x];
        while (x % d == 0) {
          x /= d;
        }
      }
      for (int j = 0; j < (1 << sz); ++j) {
        int rr = 1, ee = 0;
        for (int k = 0; k < sz; ++k)
          if (bit(j, k)) rr *= qq[k], ee ^= 1;
        if (ee == 0)
          ret = (ret + f[1][i] * ans[rr] % p) % p;
        else
          ret = (ret - f[1][i] * ans[rr] % p + p) % p;
      }
    }
  }
  return ret;
}
int main() {
  ios ::sync_with_stdio(false);
  cin >> n >> m >> l >> r >> p;
  p += p;
  for (int i = 0; i <= n; ++i) {
    add(1, 0, n - i);
    if (i > 0) add(1, 1, i);
  }
  for (int i = 0; i <= m; ++i) {
    add(2, 0, m - i);
    if (i > 0) add(2, 1, i);
  }
  l = l * l;
  r = r * r;
  for (int x = 1; x <= 2; ++x) {
    long long d = f[x][0];
    for (int i = 1; i <= max(n, m); ++i) {
      d += f[x][i];
      d %= p;
      if (d < 0) d += p;
      f[x][i] = d;
    }
  }
  for (int i = 2; i <= max(n, m); ++i)
    if (P[i] == 0) {
      int j = i;
      while (j <= max(n, m)) {
        P[j] = i;
        j += i;
      }
    }
  cout << (calc(r) - calc(l - 1) + p) % p / 2 << endl;
  return 0;
}
