#include <bits/stdc++.h>
using namespace std;
unsigned int n, a, b, c, d;
inline unsigned int f(unsigned int x) { return ((a * x + b) * x + c) * x + d; }
inline unsigned int geta(unsigned int x) {
  unsigned int ans = 0, p = x;
  const unsigned int lim = n / p;
  while (p <= n) {
    ans += n / p;
    if (p > lim) break;
    p *= x;
  }
  return ans;
}
const int N = 17330;
int mark[N];
int p[N], sz;
void sieve(unsigned int L, unsigned int R) {
  memset(mark, 0, sizeof mark);
  for (int i = 0; i < sz; i++) {
    for (unsigned int j = (L + p[i] - 1) / p[i] * p[i]; j <= R; j += p[i])
      mark[j - L] = 1;
  }
}
int main() {
  scanf("%u %u %u %u %u", &n, &a, &b, &c, &d);
  unsigned int ans = 0;
  for (int i = 2; i < N; i++)
    if (!mark[i]) {
      p[sz++] = i;
      ans += f(i) * geta(i);
      for (int j = i + i; j < N; j += i) mark[j] = 1;
    }
  for (unsigned int i = N; i < n; i += N) {
    sieve(i, i + N - 1);
    for (unsigned int j = 0; j < N; j++)
      if (!mark[j]) ans += f(j + i) * geta(j + i);
  }
  printf("%u\n", ans);
}
