#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e8 + 10;
bitset<MAXN> vis;
unsigned n, A, B, C, D, ans;
unsigned f(unsigned x) { return A * x * x * x + B * x * x + C * x + D; }
unsigned Get(unsigned x) {
  unsigned ans = 0;
  for (int i = 1; i <= n / x; i *= x) ans += n / (i * x);
  return ans * f(x);
}
int main() {
  cin >> n >> A >> B >> C >> D;
  ans = Get(2) + Get(3);
  for (unsigned i = 5; i <= n; ++i) {
    if (i % 2 == 0 || i % 3 == 0) continue;
    if (!vis[i / 3]) {
      ans += Get(i);
      for (unsigned j = i; j <= n / i; ++j) {
        if (i * j % 3 == 0 || i * j % 2 == 0) continue;
        vis[i * j / 3] = 1;
      }
    }
  }
  cout << ans << endl;
}
