#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e4;
const int STEP = 2e6 * 32;
bool p[N];
unsigned int prime[N];
int pos[N], primecnt;
unsigned int isp[STEP / 32];
void init() {
  for (int i = 2; i < N; i++)
    if (!p[i]) {
      for (int j = i + i; j < N; j += i) p[j] = 1;
      prime[primecnt++] = i;
    }
}
int n;
unsigned int A, B, C, D;
int main() {
  init();
  ios_base::sync_with_stdio(false);
  cin >> n >> A >> B >> C >> D;
  if (n <= 11) {
    unsigned int ans = 0;
    for (int i = 0; i < primecnt && prime[i] <= n; i++) {
      int x = n / prime[i];
      unsigned int v = A * prime[i] * prime[i] * prime[i] +
                       B * prime[i] * prime[i] + C * prime[i] + D;
      unsigned int c = 0;
      while (x) c += x, x /= prime[i];
      ans += v * c;
    }
    cout << ans << endl;
    return 0;
  }
  int lim;
  for (lim = 0; lim < primecnt && prime[lim] * prime[lim] <= n; lim++)
    ;
  for (int i = 0; i < lim; i++) {
    pos[i] = (prime[lim - 1] + 1) / prime[i] * prime[i];
    if (pos[i] <= prime[lim - 1]) pos[i] += prime[i];
  }
  unsigned int ans = 0;
  for (int i = 0; i < lim; i++) {
    int x = n / prime[i];
    unsigned int v = A * prime[i] * prime[i] * prime[i] +
                     B * prime[i] * prime[i] + C * prime[i] + D;
    unsigned int c = 0;
    while (x) c += x, x /= prime[i];
    ans += v * c;
  }
  for (int st = prime[lim - 1] + 1; st <= n; st += STEP) {
    memset(isp, 0, sizeof isp);
    for (int i = 0; i < lim; i++) {
      while (pos[i] < st + STEP) {
        isp[(pos[i] - st) / 32] |= (1 << ((pos[i] - st) % 32));
        pos[i] += prime[i];
      }
    }
    int en = min(st + STEP - 1, n) - st;
    for (int i = 0; i <= en; i++)
      if (!(isp[i / 32] & (1 << (i % 32)))) {
        unsigned int p = st + i;
        ans += (A * p * p * p + B * p * p + C * p + D) * (n / p);
      }
  }
  cout << ans << endl;
  return 0;
}
