#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;
mt19937_64 randGen(system_clock().now().time_since_epoch().count());
inline void raiseError(string errorCode) {
  cerr << "Error : " << errorCode << endl;
  exit(42);
}
signed main() {
  ios_base::sync_with_stdio(false);
  uint32_t n, A, B, C, D;
  cin >> n >> A >> B >> C >> D;
  uint32_t ans = 0;
  const uint32_t rng = 100000;
  vector<char> prime(rng, true);
  prime[0] = prime[1] = false;
  assert((uint64_t)rng * rng > n);
  for (uint32_t i = 2; i < rng; i++) {
    if (prime[i]) {
      uint32_t f = D + i * (C + i * (B + i * A));
      uint32_t j = n, knt = 0;
      while (j) {
        j /= i;
        knt += j;
      }
      if (knt != 0) {
        ans += f * knt;
      }
      for (uint32_t j = i * i; j < rng; j += i) {
        prime[j] = false;
      }
    }
  }
  for (uint32_t l = rng; l <= n; l += rng) {
    uint32_t r = min(l + rng, n + 1);
    vector<char> pp(r - l, true);
    for (uint32_t i = 2; i < rng; i++) {
      if (prime[i]) {
        for (uint32_t j = (l + i - 1) / i * i; j < r; j += i) {
          pp[j - l] = false;
        }
      }
    }
    for (uint32_t i = l; i < r; i++) {
      if (pp[i - l]) {
        uint32_t f = D + i * (C + i * (B + i * A));
        uint32_t knt = n / i;
        if (knt != 0) {
          ans += f * knt;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
