#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
unsigned int n, ans, A, B, C, D;
bitset<75000010> p;
bitset<20000> tmp;
unsigned int F(unsigned int x) { return A * x * x * x + B * x * x + C * x + D; }
int main() {
  cin >> n >> A >> B >> C >> D;
  if (n == 1) printf("0\n"), exit(0);
  if (n == 2) {
    cout << F(2);
    exit(0);
  }
  if (n == 3) {
    cout << F(2) + F(3);
    exit(0);
  }
  bool fir = 0;
  for (unsigned int i = 2; i <= n / 2; i++)
    if (i == 2 || i % 2 == 1 && !p[i / 2]) {
      unsigned int t = F(i), m = n;
      while (m) ans += t * (m / i), m /= i;
      if (1LL * i * i > n) continue;
      for (unsigned int j = i * i; j <= n / 2; j += i)
        if (j & 1) p[j / 2] = 1;
    }
  for (int i = 0; i < 20000; i++) tmp[i] = p[i];
  p.reset();
  for (unsigned int i = 3; i * i <= n; i++)
    if (i % 2 == 1 && !tmp[i / 2]) {
      for (unsigned int j = i * i; j <= n; j += i) {
        if (j > n / 2 && j % 2 == 1) p[(j - n / 2) / 2] = 1;
      }
    }
  for (unsigned int i = n / 2 + 1; i <= n; i++)
    if ((i & 1) && !p[(i - n / 2) / 2]) {
      unsigned int t = F(i), m = n;
      while (m) ans += t * (m / i), m /= i;
    }
  cout << ans << endl;
  return 0;
}
