#include <bits/stdc++.h>
using namespace std;
vector<long long int> primes;
const long long int mod = 4294967296LL;
int n;
long long int a, b, c, d;
long long int ans = 0;
long long int f(long long int p) {
  long long int v = (a * p + b) % mod;
  v = (v * p + c) % mod;
  v = (v * p + d) % mod;
  return v;
}
long long int gd(int p) {
  int tmp = n;
  long long int cnt = 0;
  while (tmp) {
    cnt += tmp / p;
    tmp /= p;
  }
  return cnt;
}
long long int g(int p) {
  long long int e = 0;
  long long int q = p;
  while (q <= n) {
    e += (n / q);
    q *= p;
  }
  return e;
}
void simpleSieve(int limit, vector<int> &prime) {
  bool mark[limit + 1];
  memset(mark, true, sizeof(mark));
  for (int p = 2; p * p <= limit; p++) {
    if (mark[p] == true) {
      for (int i = p * 2; i <= limit; i += p) {
        mark[i] = false;
      }
    }
  }
  for (int p = 2; p <= limit; p++) {
    if (mark[p] == true) {
      prime.push_back(p);
      ans = (ans + f(p) * g(p)) % mod;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> a >> b >> c >> d;
  int limit = floor(sqrt(n)) + 1;
  vector<int> prime;
  simpleSieve(limit, prime);
  int low = limit;
  int high = 2 * limit;
  while (low < n) {
    if (high >= n) high = n;
    bool mark[limit + 1];
    memset(mark, true, sizeof(mark));
    for (int i = 0; i < prime.size(); i++) {
      int loLim = floor(low / prime[i]) * prime[i];
      if (loLim < low) {
        loLim += prime[i];
      }
      for (int j = loLim; j <= high; j += prime[i]) {
        mark[j - low] = false;
      }
    }
    for (long long int i = low; i <= high; i++) {
      if (mark[i - low] == true) {
        ans = (ans + f(i) * g(i)) % mod;
      }
    }
    low = low + limit;
    high = high + limit;
  }
  cout << ans << "\n";
  return 0;
}
