#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e8 + 5;
namespace shit {
template <int N>
class bitset {
 public:
  unsigned long long data[N];
  bool operator[](int x) { return data[x / 64] & (1ull << (x % 64)); };
  void set(int x) { data[x / 64] |= (1ull << (x % 64)); }
};
};  // namespace shit
bitset<MAXN / 3> isprime;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  unsigned a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  unsigned ans = 0;
  auto f = [&](unsigned x) {
    unsigned ret = 0;
    ret += a;
    ret *= x;
    ret += b;
    ret *= x;
    ret += c;
    ret *= x;
    ret += d;
    return ret;
  };
  auto cal = [&](unsigned p) {
    unsigned xx = 0;
    long long now = p;
    xx = f(p);
    while (now <= n) {
      ans += xx * (n / now);
      now *= p;
    }
  };
  cal(2);
  cal(3);
  auto getindex = [](int x) {
    int ret = x / 6;
    ret <<= 1;
    if (x % 6 == 5) ret++;
    return ret;
  };
  for (int i = 2; i <= n; i++) {
    if (i % 6 == 1 || i % 6 == 5) {
      if (!isprime[getindex(i)]) {
        cal(i);
      }
      if (i <= 2e4)
        for (int j = i * i; j <= n; j += i) {
          if (j % 6 == 1 || j % 6 == 5) {
            isprime.set(getindex(j));
          }
        }
    }
  }
  cout << ans;
  return 0;
}
