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;
int get() {
  char c;
  while (c = getchar(), (c < '0' || c > '9') && (c != '-'))
    ;
  bool flag = (c == '-');
  if (flag) c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return flag ? -x : x;
}
void output(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, data[10];
  while (x) {
    data[len++] = x % 10;
    x /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
  putchar('\n');
}
long long mod;
int mu[100001];
void init() {
  int total = 0;
  static bool flag[100001];
  static int prime[100000];
  memset(flag, 0, sizeof(flag));
  mu[1] = 1;
  for (int i = 2; i <= 100000; i++) {
    if (!flag[i]) {
      prime[total++] = i;
      mu[i] = -1;
    }
    for (int j = 0; j < total && i * prime[j] <= 100000; j++) {
      int k = i * prime[j];
      flag[k] = true;
      if (i % prime[j])
        mu[k] = -mu[i];
      else {
        mu[k] = 0;
        break;
      }
    }
  }
}
long long solve(long long n, long long m, long long d) {
  if (d <= 0) return 0;
  long long ans = (n * m * 2 + n + m) % mod;
  for (long long k = 1; k <= n && k <= m; k++)
    if (mu[k])
      for (long long p = 1; p * k <= n && p * p <= d / (k * k); p++) {
        int q = m / k;
        q = min(q, (int)sqrt(d / (k * k) - p * p));
        if (!q) continue;
        long long t0 = (n - p * k + 1) % mod;
        long long t1 = (q * (m + 1) - k * q * (q + 1) / 2) % mod;
        if (mu[k] > 0)
          ans += t0 * t1 * 2;
        else
          ans -= t0 * t1 * 2;
        ans %= mod;
        if (ans < 0) ans += mod;
      }
  return ans;
}
int main() {
  init();
  long long n = get(), m = get(), l = get(), r = get();
  mod = get();
  long long ans = solve(n, m, r * r) - solve(n, m, l * l - 1);
  if (ans < 0) ans += mod;
  output(ans);
  return 0;
}
