#include <bits/stdc++.h>
using namespace std;
const int maxn = 75000000;
bitset<maxn> p;
vector<int> pri;
int n;
unsigned int a, b, c, d;
unsigned int ans = 0;
void init(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (!p[i]) {
      pri.push_back(i);
      for (int j = i; j * j <= n; j += i) p[j] = 1;
    }
  }
}
void add(int x) {
  unsigned sum = 0;
  int m = n;
  while (m >= x) {
    sum += m / x;
    m /= x;
  }
  ans += sum * (a * x * x * x + b * x * x + c * x + d);
}
int main() {
  scanf("%d%u%u%u%u", &n, &a, &b, &c, &d);
  init(n);
  int L = 2;
  while (L <= n) {
    p.reset();
    int R = min(L + maxn - 1, n);
    for (auto x : pri) {
      int now = L / x * x;
      while (now < L || now == x) now += x;
      for (; now <= R; now += x) p[now - L] = 1;
    }
    for (int i = 0; i + L <= R; i++)
      if (!p[i]) add(i + L);
    L = R + 1;
  }
  cout << ans << endl;
  return 0;
}
