#include <bits/stdc++.h>
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
bitset<100000001> p;
unsigned int n, a, b, c, d, ans = 0;
inline void add(unsigned int i) {
  unsigned int f = a * i * i * i + b * i * i + c * i + d, t = i;
  while (true) {
    ans += f * (n / t);
    if (t > (n + i - 1) / i) break;
    t *= i;
  }
}
int32_t main() {
  cin >> n >> a >> b >> c >> d;
  add(2);
  add(3);
  for (unsigned int i = 5, t = 2; i <= n; i += t, t = 6 - t) {
    if (!p[i / 3]) {
      add(i);
      if (i > (n + i - 1) / i) continue;
      for (unsigned int j = i * i, v = t; j <= n; j += v * i, v = 6 - v)
        p[j / 3] = 1;
    }
  }
  cout << ans;
  return 0;
}
