#include <bits/stdc++.h>
using namespace std;
bitset<100000011> s;
unsigned n, a, b, c, d, ans, v;
inline void exlogf(int x) {
  int f = ((a * x + b) * x + c) * x + d;
  int g = n;
  for (; g; ans += f * (g /= x))
    ;
}
inline int pos(int x) {
  int p = (x / 6) << 1;
  if (x % 6 == 5) p |= 1;
  return p;
}
int main() {
  scanf("%u%u%u%u%u", &n, &a, &b, &c, &d);
  exlogf(2), exlogf(3);
  for (register int i = 1; i <= n; ++i) {
    v = i * 6 - 1;
    if (v > n) break;
    if (!s[pos(v)]) {
      exlogf(v);
      if (v <= n / v)
        for (register int j = v / 6; j <= n; ++j) {
          if (1ll * v * (j * 6 - 1) > n) break;
          s[pos(v * (j * 6 - 1))] = 1;
          if (1ll * v * (j * 6 + 1) > n) break;
          s[pos(v * (j * 6 + 1))] = 1;
        }
    }
    v = i * 6 + 1;
    if (v > n) break;
    if (!s[pos(v)]) {
      exlogf(v);
      if (v <= n / v)
        for (register int j = v / 6; j <= n; ++j) {
          if (1ll * v * (j * 6 - 1) > n) break;
          s[pos(v * (j * 6 - 1))] = 1;
          if (1ll * v * (j * 6 + 1) > n) break;
          s[pos(v * (j * 6 + 1))] = 1;
        }
    }
  }
  printf("%u\n", ans);
  return 0;
}
