#include <bits/stdc++.h>
#pragma GCC optimize("-O3", "-funroll-all-loops")
using namespace std;
unsigned np[100000000 / 32 + 5];
bitset<200000> nps;
int n, sp[23333], sn, pnn;
unsigned A, B, C, D, ans;
inline void deal(unsigned p) {
  unsigned F = ((A * p + B) * p + C) * p + D, g = n;
  while (g /= p) ans += F * g;
}
int main() {
  scanf("%d%u%u%u%u", &n, &A, &B, &C, &D);
  int w = sqrt(n);
  w += 3;
  if (w > n) w = n;
  nps[1] = 1;
  for (int i = 2; i <= w; ++i)
    if (!nps[i]) {
      deal(i);
      sp[++sn] = i;
      for (int j = i + i; j <= w; j += i) nps[j] = 1;
    }
  for (int p = w + 1; p <= n;) {
    memset(&np, 0, sizeof np);
    int r = min(p + 100000000 - 3, n), rp = r - p;
    for (int j = 1; j <= sn; ++j) {
      int t = sp[j], x = t;
      x += (p - t) / t * t;
      while (x < p) x += t;
      x -= p;
      while (x <= rp) np[x >> 5] |= 1u << (x & 31), x += t;
    }
    for (int j = 0; j <= rp; ++j)
      if ((np[j >> 5]) & (1u << (j & 31)))
        ;
      else
        deal(j + p);
    p = r + 1;
  }
  printf("%u\n", ans);
}
