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 MAX = 300000;
long long M, N, L, H, B;
long long factor[MAX + 10];
vector<long long> factors[MAX + 10];
void sieve() {
  for (int i = 2; i <= MAX; i++) factor[i] = i;
  for (int i = 2; i <= MAX; i++) {
    if (factor[i] == i) {
      for (int j = 2 * i; j <= MAX; j += i) factor[j] = i;
    }
  }
}
void get_factors() {
  for (int i = 2; i <= MAX; i++) {
    int k = i;
    while (k > 1) {
      factors[i].push_back(factor[k]);
      int l = k;
      while (l % factor[k] == 0) l /= factor[k];
      k = l;
    }
  }
}
long long totient(long long n, long long k) {
  if (n == 0) return 0;
  if (n == 1) return (k * M - (k * (k + 1) / 2));
  long long total = 0;
  for (int b = 0; b < (1 << factors[n].size()); b++) {
    long long sign = 1;
    long long num = 1;
    for (int i = 0; i < factors[n].size(); i++) {
      if (b & (1 << i)) {
        sign *= -1;
        num *= factors[n][i];
      }
    }
    total += sign * ((k / num) * M - ((k / num) * (k / num + 1) / 2) * num);
  }
  return total;
}
inline long long Floor(double d) { return (long long)(d + 1e-8); }
inline long long Ceil(double d) { return (long long)(d + 1.0 - 1e-8); }
int main() {
  sieve();
  get_factors();
  cin >> M >> N >> L >> H >> B;
  M++, N++;
  long long total = 0;
  for (long long dx = 1; dx <= H - 1 && dx <= N - 1; dx++) {
    long long dy_low, dy_high;
    if (dx >= L)
      dy_low = 0;
    else
      dy_low = Ceil(sqrt(L * L - dx * dx));
    if (dy_low >= M) continue;
    dy_high = Floor(sqrt(H * H - dx * dx));
    dy_low = max(dy_low, 1LL);
    dy_high = max(dy_high, 1LL);
    dy_low = min(dy_low, M - 1);
    dy_high = min(dy_high, M - 1);
    total += 2LL * (totient(dx, dy_high) - totient(dx, dy_low - 1)) * (N - dx);
    total %= B;
  }
  if (L == 1) {
    total += (N * (M - 1) + M * (N - 1));
    total %= B;
  }
  cout << total << endl;
  return 0;
}
