#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3")
using namespace std;
inline void opting() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
}
unsigned int inp() {
  unsigned int x;
  cin >> x;
  return x;
}
void make_unique(vector<unsigned int> &vec, bool sorted = false) {
  if (sorted) sort((vec).begin(), (vec).end());
  vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
}
void file_edit(bool reader = true, bool writer = false) {
  if (reader) freopen("Test_input.txt", "r", stdin);
  if (writer) freopen("Test_output.txt", "w", stdout);
}
const unsigned int SQRT = 17400, lg = 20, inlim = 2147483647;
const unsigned int maxn = 3e8 + 10, inf = 1e9 + 420, delta = 1e9 + 9;
const unsigned int sz = (4 * maxn) / 15 + 10;
bitset<sz> mark;
unsigned int ans, n, A, B, C, D;
inline unsigned int calcing(const unsigned int &x) {
  unsigned int m = n;
  unsigned int gg = 0;
  while (m) {
    m /= x;
    gg += m;
  }
  gg *= (x * x * x * A + x * x * B + x * C + D);
  return gg;
}
unsigned int pos[] = {100, 0,   100, 100, 100, 100, 100, 1,   100, 100, 100,
                      2,   100, 3,   100, 100, 100, 4,   100, 5,   100, 100,
                      100, 6,   100, 100, 100, 100, 100, 7,   100};
int main() {
  opting();
  cin >> n >> A >> B >> C >> D;
  ans += calcing(2);
  ans += calcing(3);
  ans += calcing(5);
  for (unsigned int x = 6; x <= n; x++) {
    unsigned int r = x % 30;
    if (pos[r] == 100 or mark[(x / 30) * 8 + pos[r]]) continue;
    ans += calcing(x);
    if (x > SQRT) continue;
    for (unsigned int j = x * x; j <= n; j += x) {
      r = j % 30;
      if (pos[r] == 100) continue;
      mark[(j / 30) * 8 + pos[r]] = true;
    }
  }
  cout << ans << endl;
}
