#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int MAX_N = 100000;
int Rows, Columns, Lower, Upper, Mod, Answer;
vector<int> PrimeFactors[MAX_N + 1];
void Eratosthenes() {
  for (int i = 2; i <= MAX_N; ++i)
    if (PrimeFactors[i].empty())
      for (int j = i; j <= MAX_N; j += i) PrimeFactors[j].push_back(i);
}
inline int GetBit(const int mask, const int bit) { return (mask >> bit) & 1; }
void Solve() {
  Eratosthenes();
  Answer = 0;
  for (int width = 1, lower = Lower, upper = Upper;
       width <= Columns && width <= Upper; ++width) {
    for (; lower > 1 && 1LL * Lower * Lower - 1LL * width * width <=
                            1LL * (lower - 1) * (lower - 1);
         --lower)
      ;
    for (; 1LL * Upper * Upper - 1LL * width * width < 1LL * upper * upper;
         --upper)
      ;
    if (lower > upper || lower > Rows) continue;
    int sum = 0;
    for (int mask = 0; mask < (1 << int(PrimeFactors[width].size())); ++mask) {
      int sign = 1, product = 1;
      for (int i = 0; i < int(PrimeFactors[width].size()); ++i) {
        if (GetBit(mask, i) == 1) {
          sign = -sign;
          product *= PrimeFactors[width][i];
        }
      }
      int count = min(Rows, upper) / product;
      sum = (sum +
             sign * ((1LL * count * (Rows + 1) -
                      1LL * (1LL * count * (count + 1) / 2) * product) %
                     Mod) +
             Mod) %
            Mod;
      count = (lower - 1) / product;
      sum = (sum -
             sign * ((1LL * count * (Rows + 1) -
                      1LL * (1LL * count * (count + 1) / 2) * product) %
                     Mod) +
             Mod) %
            Mod;
    }
    Answer = (Answer + 1LL * (Columns - width + 1) * sum) % Mod;
  }
  Answer = (2 * Answer) % Mod;
  if (Lower <= 1 && 1 <= Upper)
    Answer =
        (Answer + 1LL * Rows * (Columns + 1) + 1LL * (Rows + 1) * Columns) %
        Mod;
}
void Read() { cin >> Rows >> Columns >> Lower >> Upper >> Mod; }
void Print() { cout << Answer << "\n"; }
int main() {
  Read();
  Solve();
  Print();
  return 0;
}
