#include <bits/stdc++.h>
using namespace std;
const int P = (int)1e8;
const int MX = P + 5;
bitset<MX> flg;
bool prime[(int)1e5 + 5];
void sieve(int n) {
  int x, y, z, t;
  for (z = 1; z <= 5; z += 4) {
    for (y = z; y * y <= n; y += 6) {
      for (x = 1; (t = 4 * x * x + y * y) <= n; x++) flg[t] = !flg[t];
      for (x = y + 1; (t = 3 * x * x - y * y) <= n; x += 2) flg[t] = !flg[t];
    }
  }
  for (z = 2; z <= 4; z += 2) {
    for (y = z; y * y <= n; y += 6) {
      for (x = 1; (t = 3 * x * x + y * y) <= n; x += 2) flg[t] = !flg[t];
      for (x = y + 1; (t = 3 * x * x - y * y) <= n; x += 2) flg[t] = !flg[t];
    }
  }
  for (y = 3; y * y <= n; y += 6) {
    for (z = 1; z <= 2; z++) {
      for (x = z; (t = 4 * x * x + y * y) <= n; x += 3) flg[t] = !flg[t];
    }
  }
  for (x = 5; x * x <= n; x++) {
    if (!flg[x]) continue;
    for (y = x * x; y <= n; y += x * x) flg[y] = 0;
  }
  flg[2] = flg[3] = 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  sieve(P);
  for (int i = 2; i < (int)1e5; i++) prime[i] = flg[i];
  int n;
  unsigned int A, B, C, D;
  cin >> n >> A >> B >> C >> D;
  unsigned int cur, ans = 0, cnt = 0;
  long long j;
  int lim = min(n, P);
  for (int i = 2; i <= lim; i++)
    if (flg[i]) {
      cur = A * i * i * i + B * i * i + C * i + D;
      cnt = 0;
      for (j = i; j <= (long long)n; j *= i) cnt += n / (unsigned int)j;
      ans += cur * cnt;
    }
  for (int step = 1; step < 3; step++)
    if (n > step * P) {
      for (int i = 0; i < MX; i++) flg[i] = 0;
      int jj;
      for (int i = 2; (long long)i * i <= (long long)(step + 1) * P; i++)
        if (prime[i]) {
          jj = (step * P) / i * i;
          if (jj <= (step * P)) jj += i;
          for (; jj <= (step + 1) * P; jj += i) flg[jj - step * P] = 1;
        }
      lim = min(n, (step + 1) * P);
      for (int i = step * P + 1; i <= lim; i++)
        if (!flg[i - step * P]) {
          cur = A * i * i * i + B * i * i + C * i + D;
          cnt = 0;
          for (j = i; j <= (long long)n; j *= i) cnt += n / (unsigned int)j;
          ans += cur * cnt;
        }
    }
  cout << ans << endl;
  return 0;
}
